Commit afd02e08 authored by Teng Qin's avatar Teng Qin Committed by Facebook Github Bot

Ensure FOLLY_SDT's Semaphore is in an allocated section

Summary:
Currently `FOLLY_SDT`'s Semaphore is just an global variable at where it was defined. Since it's initialized to 0 it will be put into the `.bss` section. It works fine currently, especially for Executable binaries, because tools, in particular BCC, will be writing to the virtual address directly.

However, recent patches to Linux Kernel supports handling Semaphore (reference counter) natively along with the uprobe event, and it requires the Semaphore address to be allocated in the binary file so Kernel can find correct VMA for the address, especially for Shared Object binaries.

This Diff makes `FOLLY_SDT_DEFINE_SEMAPHORE` to put the Semaphore into a `PROGBITS` section `.probes` that is writeable and allocated. This is a practice compatible with SystemTap's USDT implementation, where the Semaphores also reside in the `.probes` section, as can be found in CPython, libc, MySQL, PostgresSQL, and many applications already.

Reviewed By: yfeldblum

Differential Revision: D10319732

fbshipit-source-id: 67ac0e55cc10cf1425a754d88cae0165b89ee993
parent 1034be9b
......@@ -31,6 +31,9 @@
#define FOLLY_SDT_NOTE_NAME "stapsdt"
#define FOLLY_SDT_NOTE_TYPE 3
// Semaphore variables are put in this section
#define FOLLY_SDT_SEMAPHORE_SECTION ".probes"
// Size of address depending on platform.
#ifdef __LP64__
#define FOLLY_SDT_ASM_ADDR .8byte
......@@ -94,7 +97,8 @@
#define FOLLY_SDT_DEFINE_SEMAPHORE(provider, name) \
extern "C" { \
volatile unsigned short FOLLY_SDT_SEMAPHORE(provider, name) = 0; \
volatile unsigned short FOLLY_SDT_SEMAPHORE(provider, name) \
__attribute__((section(FOLLY_SDT_SEMAPHORE_SECTION), used)) = 0; \
}
#define FOLLY_SDT_DECLARE_SEMAPHORE(provider, name) \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment