summaryrefslogtreecommitdiff
path: root/test.c
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2016-12-14 16:04:26 -0800
committerMatt Turner <mattst88@gmail.com>2016-12-14 16:19:48 -0800
commit838ebbcf92352217ea7ed16e0894ea585a357f88 (patch)
treef4a4a1217c84210da3f785e0836d23ab10e5896e /test.c
parent9728a8bdc1d882acf534df6a86dbb435146a5ca8 (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 'test.c')
-rw-r--r--test.c18
1 files changed, 4 insertions, 14 deletions
diff --git a/test.c b/test.c
index e8dae35..fbea6b4 100644
--- a/test.c
+++ b/test.c
@@ -30,27 +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);
-
- const ElfW(Nhdr) *nhdr = build_id_find_nhdr();
- if (!nhdr)
+ const struct note *note = build_id_find_nhdr("");
+ 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++) {