diff options
author | Matt Turner <mattst88@gmail.com> | 2016-12-14 16:04:26 -0800 |
---|---|---|
committer | Matt Turner <mattst88@gmail.com> | 2016-12-14 16:19:48 -0800 |
commit | 838ebbcf92352217ea7ed16e0894ea585a357f88 (patch) | |
tree | f4a4a1217c84210da3f785e0836d23ab10e5896e /so-test.c | |
parent | 9728a8bdc1d882acf534df6a86dbb435146a5ca8 (diff) |
Use dl_iterate_phdr() instead of a linker script.
According to Mike Frysinger [1] it is not reliable to read ELF sections
at runtime, which the previous method involving the linker script was
doing.
Instead, use dl_iterate_phdr() to find the build id.
[1] https://sourceware.org/ml/binutils/2016-12/msg00207.html
Diffstat (limited to 'so-test.c')
-rw-r--r-- | so-test.c | 20 |
1 files changed, 4 insertions, 16 deletions
@@ -30,29 +30,17 @@ int main(int argc, char *argv[]) { - extern char etext, edata, end; - extern const char __note_gnu_build_id_end[] __attribute__((weak)); - extern const char __note_gnu_build_id_start[] __attribute__((weak)); - printf("Executable:\n"); - printf(" program text (etext) %10p\n", &etext); - printf(" initialized data (edata) %10p\n", &edata); - printf(" uninitialized data (end) %10p\n", &end); - printf(" note section start %10p\n", __note_gnu_build_id_start); - printf(" note section end %10p\n", __note_gnu_build_id_end); - - so_print(); - - const ElfW(Nhdr) *nhdr = build_id_find_nhdr(); - if (!nhdr) + const struct note *note = build_id_find_nhdr("./libbuild-id.so"); + if (!note) return -1; - ElfW(Word) len = build_id_length(nhdr); + ElfW(Word) len = build_id_length(note); unsigned char *build_id = malloc(len * sizeof(char)); if (!build_id) return -1; - build_id_read(nhdr, build_id); + build_id_read(note, build_id); printf("Build ID: "); for (ElfW(Word) i = 0; i < len; i++) { |