summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2018-11-12 23:34:24 +0100
committerMark Wielaard <mark@klomp.org>2018-11-13 13:46:40 +0100
commit72e30c2e0cb49a9a300667fdd5ff09082f717950 (patch)
treed8aa22a90873f98e00df21f33c0ae40c520f0de5 /src
parent7a3f6fe60b8519b5372f5a5521ccbac59411f33f (diff)
Handle GNU Build Attribute ELF Notes.
GNU Build Attribute ELF Notes are generated by the GCC annobin plugin and described at https://fedoraproject.org/wiki/Toolchain/Watermark Unfortunately the constants aren't yet described in the standard glibc elf.h so they have been added to the elfutils specific elf-knowledge.h. The notes abuse the name owner field to encode some data not in the description. This makes it a bit hard to parse. We have to match the note owner name prefix (to "GA") to be sure the type is valid. We also cannot rely on the owner name being a valid C string since the attribute name and value can contain zero (terminators). So pass around namesz to the ebl note parsing functions. eu-elflint will recognize and eu-readelf -n will now show the notes: Note section [27] '.gnu.build.attributes' of 56080 bytes at offset 0x114564: Owner Data size Type GA 16 GNU Build Attribute OPEN Address Range: 0x2f30f - 0x2f30f VERSION: "3p8" GA 0 GNU Build Attribute OPEN TOOL: "gcc 8.2.1 20180801" GA 0 GNU Build Attribute OPEN "GOW": 45 GA 0 GNU Build Attribute OPEN STACK_PROT: 0 GA 0 GNU Build Attribute OPEN "stack_clash": TRUE GA 0 GNU Build Attribute OPEN "cf_protection": 0 GA 0 GNU Build Attribute OPEN "GLIBCXX_ASSERTIONS": TRUE GA 0 GNU Build Attribute OPEN "FORTIFY": 0 GA 0 GNU Build Attribute OPEN PIC: 3 GA 0 GNU Build Attribute OPEN SHORT_ENUM: FALSE GA 0 GNU Build Attribute OPEN ABI: c001100000012 GA 0 GNU Build Attribute OPEN "stack_realign": FALSE A new test was added to run-readelf -n for the existing annobin file. Signed-off-by: Mark Wielaard <mark@klomp.org>
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog8
-rw-r--r--src/elflint.c13
-rw-r--r--src/readelf.c16
3 files changed, 35 insertions, 2 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 0ed86bbf..f014de8f 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,11 @@
+2018-11-12 Mark Wielaard <mark@klomp.org>
+
+ * elflint.c (check_note_data): Recognize NT_GNU_BUILD_ATTRIBUTE_OPEN
+ and NT_GNU_BUILD_ATTRIBUTE_OPEN.
+ * readelf.c (handle_notes_data): Handle
+ ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX. Pass nhdr.n_namesz to
+ ebl_object_note.
+
2018-11-11 Mark Wielaard <mark@klomp.org>
* readelf.c (handle_notes_data): Pass n_descsz to
diff --git a/src/elflint.c b/src/elflint.c
index dff74eee..184ca125 100644
--- a/src/elflint.c
+++ b/src/elflint.c
@@ -4344,6 +4344,19 @@ section [%2d] '%s': unknown core file note type %" PRIu32
}
goto unknown_note;
+ case NT_GNU_BUILD_ATTRIBUTE_OPEN:
+ case NT_GNU_BUILD_ATTRIBUTE_FUNC:
+ /* GNU Build Attributes store most data in the owner
+ name, which must start with the
+ ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX "GA". */
+ if (nhdr.n_namesz >= sizeof ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX
+ && strncmp (data->d_buf + name_offset,
+ ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX,
+ strlen (ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX)) == 0)
+ break;
+ else
+ goto unknown_note;
+
case 0:
/* Linux vDSOs use a type 0 note for the kernel version word. */
if (nhdr.n_namesz == sizeof "Linux"
diff --git a/src/readelf.c b/src/readelf.c
index 659e34fb..3a73710f 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -12193,10 +12193,21 @@ handle_notes_data (Ebl *ebl, const GElf_Ehdr *ehdr,
const char *name = nhdr.n_namesz == 0 ? "" : data->d_buf + name_offset;
const char *desc = data->d_buf + desc_offset;
+ /* GNU Build Attributes are weird, they store most of their data
+ into the owner name field. Extract just the owner name
+ prefix here, then use the rest later as data. */
+ bool is_gnu_build_attr
+ = strncmp (name, ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX,
+ strlen (ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX)) == 0;
+ const char *print_name = (is_gnu_build_attr
+ ? ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX : name);
+ size_t print_namesz = (is_gnu_build_attr
+ ? strlen (print_name) : nhdr.n_namesz);
+
char buf[100];
char buf2[100];
printf (gettext (" %-13.*s %9" PRId32 " %s\n"),
- (int) nhdr.n_namesz, name, nhdr.n_descsz,
+ (int) print_namesz, print_name, nhdr.n_descsz,
ehdr->e_type == ET_CORE
? ebl_core_note_type_name (ebl, nhdr.n_type,
buf, sizeof (buf))
@@ -12237,7 +12248,8 @@ handle_notes_data (Ebl *ebl, const GElf_Ehdr *ehdr,
handle_core_note (ebl, &nhdr, name, desc);
}
else
- ebl_object_note (ebl, name, nhdr.n_type, nhdr.n_descsz, desc);
+ ebl_object_note (ebl, nhdr.n_namesz, name, nhdr.n_type,
+ nhdr.n_descsz, desc);
}
}