Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22016

Access build-id at runtime

$
0
0

I am trying to figure out how to access the build-id generated by the linker at runtime.

From this page, https://linux.die.net/man/1/ld

When I build a test program like:

% gcc test.c -o test -Wl,--build-id=sha1

I can see that the build ID is present in the binary:

% readelf -n test

Displaying notes found in: .note.gnu.build-id
  Owner                 Data size   Description
  GNU                  0x00000014   NT_GNU_BUILD_ID (unique build ID bitstring)
    Build ID: 85aa97bd52ddc4dc2a704949c2545a3a9c69c6db

I would like to print this at run-time.

EDIT: Assume you can't access the elf file from which the running process was loaded (permissions, embedded/no filesystem, etc).

EDIT: the accepted answer works, but the linker does not necessarily have to place the variable at the end of the section. If there were a way to get a pointer to the start of the section, that would be more reliable.


Viewing all articles
Browse latest Browse all 22016

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>