This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Commit: Improve readelf's selection of file symbols for GNU build notes


Hi Guys,

  I am applying the attached patch to make a couple of improvements to
  readelf's selection of file symbols when display GNU build attribute
  notes.   The first is to skip the mapping symbols ($a, $x, etc) used
  by ARM and AARCH64 targets.

  The second improvement is to cope with a change in version 5 of the
  annobin gcc plugin.  With this version the file start symbol created
  by the plugin is no longer assigned to the start of the file, as this
  breaks too many other programs.  Instead the file start symbol is set
  to two bytes into the file.  So the patches changes readelf so that if
  it cannot find a symbol at the start of the file, it will look for one
  two bytes into the file.

  Tested with a large variety of different targets.

Cheers
  Nick

binutils/ChangeLog
2018-03-23  Nick Clifton  <nickc@redhat.com>

	* readelf.c (get_symbol_for_build_attribute): Skip ARM mapping
	symbols.
	(print_gnu_build_attribute_description): If no file start symbol
	could be found, look for one two bytes into the file.
	* testsuite/binutils-all/note-4-64.s: Set the address of the file
	start symbol to two bytes into the file.
	* testsuite/binutils-all/note-4-32.s: Likewise.

diff --git a/binutils/readelf.c b/binutils/readelf.c
index d0bd679032..80075c21f8 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -17502,6 +17502,13 @@ get_symbol_for_build_attribute (Filedata *       filedata,
 	if (strtab[sym->st_name] == 0)
 	  continue;
 
+	/* The AArch64 and ARM architectures define mapping symbols
+	   (eg $d, $x, $t) which we want to ignore.  */
+	if (strtab[sym->st_name] == '$'
+	    && strtab[sym->st_name + 1] != 0
+	    && strtab[sym->st_name + 2] == 0)
+	  continue;
+
 	if (is_open_attr)
 	  {
 	    /* For OPEN attributes we prefer GLOBAL over LOCAL symbols
@@ -17630,6 +17637,12 @@ print_gnu_build_attribute_description (Elf_Internal_Note *  pnote,
 
   name = NULL;
   sym = get_symbol_for_build_attribute (filedata, start, is_open_attr, & name);
+  /* As of version 5 of the annobin plugin, filename symbols are biased by 2
+     in order to avoid them being confused with the start address of the
+     first function in the file...  */
+  if (sym == NULL && is_open_attr)
+    sym = get_symbol_for_build_attribute (filedata, start + 2, is_open_attr,
+					  & name);
 
   if (end == 0 && sym != NULL && sym->st_size > 0)
     end = start + sym->st_size;
diff --git a/binutils/testsuite/binutils-all/note-4-32.d b/binutils/testsuite/binutils-all/note-4-32.d
index 567af908f2..6c9e98ef24 100644
--- a/binutils/testsuite/binutils-all/note-4-32.d
+++ b/binutils/testsuite/binutils-all/note-4-32.d
@@ -7,13 +7,13 @@
 #...
 Displaying notes found in: .gnu.build.attributes
 [ 	]+Owner[ 	]+Data size[ 	]+Description
-[ 	]+GA\$<version>3p3[ 	]+0x00000008[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x110 \(note_4.s\)
-[ 	]+GA\$<tool>gcc 7.2.1 20170915[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x110
-[ 	]+GA\*GOW:0x700[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x110
-[ 	]+GA\*<stack prot>off[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x110
-[ 	]+GA\*FORTIFY:0xff[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x110
-[ 	]+GA\*<PIC>PIC[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x110
-[ 	]+GA\!<short enum>false[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x110
-[ 	]+GA\*<ABI>0x[0-9a-f]+[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x100 to 0x110
-[ 	]+GA\*<stack prot>strong[ 	]+0x00000008[ 	]+func[ 	]+Applies to region from 0x108 to 0x10c.*
+[ 	]+GA\$<version>3p3[ 	]+0x00000008[ 	]+OPEN[ 	]+Applies to region from 0x10. to 0x110 \(note_4.s\)
+[ 	]+GA\$<tool>gcc 7.2.1 20170915[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x10. to 0x110
+[ 	]+GA\*GOW:0x700[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x10. to 0x110
+[ 	]+GA\*<stack prot>off[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x10. to 0x110
+[ 	]+GA\*FORTIFY:0xff[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x10. to 0x110
+[ 	]+GA\*<PIC>PIC[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x10. to 0x110
+[ 	]+GA\!<short enum>false[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x10. to 0x110
+[ 	]+GA\*<ABI>0x[0-9a-f]+[ 	]+0x00000000[ 	]+OPEN[ 	]+Applies to region from 0x10. to 0x110
+[ 	]+GA\*<stack prot>strong[ 	]+0x00000008[ 	]+func[ 	]+Applies to region from 0x10. to 0x10c.*
 #...
diff --git a/binutils/testsuite/binutils-all/note-4-32.s b/binutils/testsuite/binutils-all/note-4-32.s
index 09c5652f1c..20d9e7b9a4 100644
--- a/binutils/testsuite/binutils-all/note-4-32.s
+++ b/binutils/testsuite/binutils-all/note-4-32.s
@@ -1,6 +1,6 @@
 	.text
 	.org 0x100
-note_4.s:
+	.equiv note_4.s, . + 2
 	.dc.l 0
 	.dc.l 0
 
@@ -18,7 +18,7 @@ note_4.s_end:
 	.dc.l 8
 	.dc.l 0x100
 	.asciz "GA$3p3"
-	.dc.l note_4.s
+	.dc.l note_4.s - 2
 	.dc.l note_4.s_end
 
 	.dc.l 23
diff --git a/binutils/testsuite/binutils-all/note-4-64.s b/binutils/testsuite/binutils-all/note-4-64.s
index 4f532986b7..1901682bb9 100644
--- a/binutils/testsuite/binutils-all/note-4-64.s
+++ b/binutils/testsuite/binutils-all/note-4-64.s
@@ -1,6 +1,6 @@
 	.text
 	.org 0x100
-note_4.s:
+	.equiv note_4.s, . + 2
 	.dc.l 0
 	.dc.l 0
 	.dc.l 0
@@ -22,7 +22,7 @@ note_4.s_end:
 	.dc.l 16
 	.dc.l 0x100
 	.asciz "GA$3p3"
-	.8byte note_4.s
+	.8byte note_4.s - 2
 	.8byte note_4.s_end
 
 	.dc.l 23

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]