public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] [BZ #18078] FAIL: elf/check-localplt with ld from binutils 2.26
@ 2015-03-09 20:26 H.J. Lu
  2015-03-10 22:21 ` Roland McGrath
  0 siblings, 1 reply; 5+ messages in thread
From: H.J. Lu @ 2015-03-09 20:26 UTC (permalink / raw)
  To: GNU C Library

On x86, linker in binutils 2.26 and newer consolidates R_*_JUMP_SLOT with
R_*_GLOB_DAT relocation against the same symbol.  It makes R_*_JUMP_SLOT
relocations against free and malloc optional.  We should mark PLT entries
for free and malloc optional.  OK for master?

Thanks.


H.J.
--
	[BZ #18078]
	* sysdeps/unix/sysv/linux/i386/localplt.data: Mark PLT entries
	for free and malloc optional.
	* sysdeps/x86_64/localplt.data: New file.
---
 sysdeps/unix/sysv/linux/i386/localplt.data |  9 ++++++---
 sysdeps/x86_64/localplt.data               | 20 ++++++++++++++++++++
 2 files changed, 26 insertions(+), 3 deletions(-)
 create mode 100644 sysdeps/x86_64/localplt.data

diff --git a/sysdeps/unix/sysv/linux/i386/localplt.data b/sysdeps/unix/sysv/linux/i386/localplt.data
index b25abf8..9d70ba7 100644
--- a/sysdeps/unix/sysv/linux/i386/localplt.data
+++ b/sysdeps/unix/sysv/linux/i386/localplt.data
@@ -1,7 +1,10 @@
+# Linker in binutils 2.26 and newer consolidates R_X86_64_JUMP_SLOT
+# relocation with R_386_GLOB_DAT relocation against the same symbol.
+# It makes R_386_JUMP_SLOT relocations against free and malloc optional.
 libc.so: _Unwind_Find_FDE
 libc.so: calloc
-libc.so: free
-libc.so: malloc
+libc.so: free ?
+libc.so: malloc ?
 libc.so: memalign
 libc.so: realloc
 libm.so: matherr
@@ -12,4 +15,4 @@ ld.so: __libc_memalign
 ld.so: malloc
 ld.so: calloc
 ld.so: realloc
-ld.so: free
+ld.so: free ?
diff --git a/sysdeps/x86_64/localplt.data b/sysdeps/x86_64/localplt.data
new file mode 100644
index 0000000..165259a
--- /dev/null
+++ b/sysdeps/x86_64/localplt.data
@@ -0,0 +1,20 @@
+# See scripts/check-localplt.awk for how this file is processed.
+# PLT use is required for the malloc family and for matherr because
+# users can define their own functions and have library internals call them.
+# Linker in binutils 2.26 and newer consolidates R_X86_64_JUMP_SLOT
+# relocation with R_X86_64_GLOB_DAT relocation against the same symbol.
+# It makes R_X86_64_JUMP_SLOT relocations against free and malloc optional.
+libc.so: calloc
+libc.so: free ?
+libc.so: malloc ?
+libc.so: memalign
+libc.so: realloc
+libm.so: matherr
+# The dynamic loader uses __libc_memalign internally to allocate aligned
+# TLS storage. The other malloc family of functions are expected to allow
+# user symbol interposition.
+ld.so: __libc_memalign
+ld.so: malloc
+ld.so: calloc
+ld.so: realloc
+ld.so: free ?
-- 
1.9.3

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] [BZ #18078] FAIL: elf/check-localplt with ld from binutils 2.26
  2015-03-09 20:26 [PATCH] [BZ #18078] FAIL: elf/check-localplt with ld from binutils 2.26 H.J. Lu
@ 2015-03-10 22:21 ` Roland McGrath
  2015-03-11 17:02   ` H.J. Lu
  0 siblings, 1 reply; 5+ messages in thread
From: Roland McGrath @ 2015-03-10 22:21 UTC (permalink / raw)
  To: H.J. Lu; +Cc: GNU C Library

I don't think this is the way to do it.  For those cases it is mandatory
that libc is actually using the PLT entry, so we don't want a check that
would pass if libc stopped using it at all.  Perhaps instead there is a way
to modify scripts/localplt.awk and/or scripts/check-localplt.awk so that
they will grok the new linker's output as constituting use of a PLT entry.
Maybe a GLOB_DAT reloc to a symbol that's STT_FUNC is a close enough proxy?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] [BZ #18078] FAIL: elf/check-localplt with ld from binutils 2.26
  2015-03-10 22:21 ` Roland McGrath
@ 2015-03-11 17:02   ` H.J. Lu
  2015-07-14 19:43     ` H.J. Lu
  0 siblings, 1 reply; 5+ messages in thread
From: H.J. Lu @ 2015-03-11 17:02 UTC (permalink / raw)
  To: Roland McGrath; +Cc: GNU C Library

[-- Attachment #1: Type: text/plain, Size: 1152 bytes --]

On Tue, Mar 10, 2015 at 3:21 PM, Roland McGrath <roland@hack.frob.com> wrote:
> I don't think this is the way to do it.  For those cases it is mandatory
> that libc is actually using the PLT entry, so we don't want a check that
> would pass if libc stopped using it at all.  Perhaps instead there is a way
> to modify scripts/localplt.awk and/or scripts/check-localplt.awk so that
> they will grok the new linker's output as constituting use of a PLT entry.
> Maybe a GLOB_DAT reloc to a symbol that's STT_FUNC is a close enough proxy?

Here is the patch to extend local PLT reference check to support
alternate relocations.  OK for master?


-- 
H.J.
---
On x86, linker in binutils 2.26 and newer consolidates R_*_JUMP_SLOT with
R_*_GLOB_DAT relocation against the same symbol.  This patch extends
local PLT reference check to support alternate relocations.

[BZ #18078]
* scripts/check-localplt.awk: Support alternate relocations.
* scripts/localplt.awk: Also check relocations in DT_RELA/DT_REL
sections.
* sysdeps/unix/sysv/linux/i386/localplt.data: Mark free and
malloc entries with + REL R_386_GLOB_DAT.
* sysdeps/x86_64/localplt.data: New file.

[-- Attachment #2: 0001-Extend-local-PLT-reference-check.patch --]
[-- Type: text/x-patch, Size: 7061 bytes --]

From 688e958c81f230b5860b57590f45f1bc729ba2cf Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Mon, 9 Mar 2015 13:22:01 -0700
Subject: [PATCH] Extend local PLT reference check

On x86, linker in binutils 2.26 and newer consolidates R_*_JUMP_SLOT with
R_*_GLOB_DAT relocation against the same symbol.  This patch extends
local PLT reference check to support alternate relocations.

	[BZ #18078]
	* scripts/check-localplt.awk: Support alternate relocations.
	* scripts/localplt.awk: Also check relocations in DT_RELA/DT_REL
	sections.
	* sysdeps/unix/sysv/linux/i386/localplt.data: Mark free and
	malloc entries with + REL R_386_GLOB_DAT.
	* sysdeps/x86_64/localplt.data: New file.
---
 scripts/check-localplt.awk                 | 40 +++++++++++++++++++++----
 scripts/localplt.awk                       | 47 ++++++++++++++++++++++++++++++
 sysdeps/unix/sysv/linux/i386/localplt.data |  8 +++--
 sysdeps/x86_64/localplt.data               | 19 ++++++++++++
 4 files changed, 106 insertions(+), 8 deletions(-)
 create mode 100644 sysdeps/x86_64/localplt.data

diff --git a/scripts/check-localplt.awk b/scripts/check-localplt.awk
index bb1b912..3965292 100644
--- a/scripts/check-localplt.awk
+++ b/scripts/check-localplt.awk
@@ -3,9 +3,14 @@
 # Each line is either a comment starting with # or it looks like:
 #	libfoo.so: function
 # or
+#	libfoo.so: function + {RELA|REL} RELOC
+# or
 #	libfoo.so: function ?
-# The latter means that a PLT entry for function is optional in libfoo.so.
-# The former means one is required.
+# The first entry means that one is required.
+# The second entry means that one is required and relocation may also be
+# {RELA|REL} RELOC.
+# The third entry means that a PLT entry for function is optional in
+# libfoo.so.
 # The second file argument is - and this (stdin) receives the output
 # of the check-localplt program.
 
@@ -14,7 +19,10 @@ BEGIN { result = 0 }
 FILENAME != "-" && /^#/ { next }
 
 FILENAME != "-" {
-  if (NF != 2 && !(NF == 3 && $3 == "?")) {
+  if (NF == 5 && $3 == "+" && ($4 == "RELA" || $4 == "REL")) {
+    accept_type[$1 " " $2] = $4;
+    accept_reloc[$1 " " $2] = $5;
+  } else if (NF != 2 && !(NF == 3 && $3 == "?")) {
     printf "%s:%d: bad data line: %s\n", FILENAME, FNR, $0 > "/dev/stderr";
     result = 2;
   } else {
@@ -23,7 +31,7 @@ FILENAME != "-" {
   next;
 }
 
-NF != 2 {
+NF != 2 && !(NF == 4 && ($3 == "RELA" || $3 == "REL")) {
   print "Unexpected output from check-localplt:", $0 > "/dev/stderr";
   result = 2;
   next
@@ -31,7 +39,23 @@ NF != 2 {
 
 {
   key = $1 " " $2
-  if (key in accept) {
+  if ($3 == "RELA" || $3 == "REL") {
+    # Entries like:
+    # libc.so: free + RELA R_X86_64_GLOB_DAT
+    # may be ignored.
+    if (key in accept_type && accept_type[key] == $3 && accept_reloc[key] == $4) {
+      # Match
+      # libc.so: free + RELA R_X86_64_GLOB_DAT
+      delete accept_type[key]
+    }
+  } else if (NF == 2 && key in accept_reloc) {
+    # Match
+    # libc.so: free
+    # against
+    # libc.so: free + RELA R_X86_64_GLOB_DAT
+    if (key in accept_type)
+      delete accept_type[key]
+  } else if (key in accept) {
     delete accept[key]
   } else {
     print "Extra PLT reference:", $0;
@@ -49,5 +73,11 @@ END {
     }
   }
 
+  for (key in accept_type) {
+    # It's mandatory.
+    print "Missing required PLT or " accept_reloc[key] " reference:", key;
+    result = 1;
+  }
+
   exit(result);
 }
diff --git a/scripts/localplt.awk b/scripts/localplt.awk
index 84c94d1..f75b3b4 100644
--- a/scripts/localplt.awk
+++ b/scripts/localplt.awk
@@ -13,6 +13,8 @@ FILENAME != lastfile {
   }
   lastfile = FILENAME;
   jmprel_offset = 0;
+  rela_offset = 0;
+  rel_offset = 0;
   delete section_offset_by_address;
 }
 
@@ -43,6 +45,30 @@ in_relocs && relocs_offset == jmprel_offset && NF >= 5 {
   }
 }
 
+in_relocs && relocs_offset == rela_offset && NF >= 5 {
+  # Relocations against GNU_IFUNC symbols are not shown as an hexadecimal
+  # value, but rather as the resolver symbol followed by ().
+  if ($4 ~ /\(\)/) {
+    print whatfile, gensub(/@.*/, "", "g", $5), "RELA", $3
+  } else {
+    symval = strtonum("0x" $4);
+    if (symval != 0)
+      print whatfile, gensub(/@.*/, "", "g", $5), "RELA", $3
+  }
+}
+
+in_relocs && relocs_offset == rel_offset && NF >= 5 {
+  # Relocations against GNU_IFUNC symbols are not shown as an hexadecimal
+  # value, but rather as the resolver symbol followed by ().
+  if ($4 ~ /\(\)/) {
+    print whatfile, gensub(/@.*/, "", "g", $5), "REL", $3
+  } else {
+    symval = strtonum("0x" $4);
+    if (symval != 0)
+      print whatfile, gensub(/@.*/, "", "g", $5), "REL", $3
+  }
+}
+
 in_relocs { next }
 
 $1 == "Relocation" && $2 == "section" && $5 == "offset" {
@@ -62,4 +88,25 @@ $2 == "(JMPREL)" {
   next
 }
 
+$2 == "(RELA)" {
+  rela_addr = strtonum($3);
+  if (rela_addr in section_offset_by_address) {
+    rela_offset = section_offset_by_address[rela_addr];
+  } else {
+    print FILENAME ": *** DT_RELA does not match any section's address";
+    result = 2;
+  }
+  next
+}
+
+$2 == "(REL)" {
+  rel_addr = strtonum($3);
+  if (rel_addr in section_offset_by_address) {
+    rel_offset = section_offset_by_address[rel_addr];
+  } else {
+    print FILENAME ": *** DT_REL does not match any section's address";
+    result = 2;
+  }
+  next
+}
 END { exit(result) }
diff --git a/sysdeps/unix/sysv/linux/i386/localplt.data b/sysdeps/unix/sysv/linux/i386/localplt.data
index b25abf8..2e03821 100644
--- a/sysdeps/unix/sysv/linux/i386/localplt.data
+++ b/sysdeps/unix/sysv/linux/i386/localplt.data
@@ -1,7 +1,9 @@
+# Linker in binutils 2.26 and newer consolidates R_X86_64_JUMP_SLOT
+# relocation with R_386_GLOB_DAT relocation against the same symbol.
 libc.so: _Unwind_Find_FDE
 libc.so: calloc
-libc.so: free
-libc.so: malloc
+libc.so: free + REL R_386_GLOB_DAT
+libc.so: malloc + REL R_386_GLOB_DAT
 libc.so: memalign
 libc.so: realloc
 libm.so: matherr
@@ -12,4 +14,4 @@ ld.so: __libc_memalign
 ld.so: malloc
 ld.so: calloc
 ld.so: realloc
-ld.so: free
+ld.so: free + REL R_386_GLOB_DAT
diff --git a/sysdeps/x86_64/localplt.data b/sysdeps/x86_64/localplt.data
new file mode 100644
index 0000000..d140476
--- /dev/null
+++ b/sysdeps/x86_64/localplt.data
@@ -0,0 +1,19 @@
+# See scripts/check-localplt.awk for how this file is processed.
+# PLT use is required for the malloc family and for matherr because
+# users can define their own functions and have library internals call them.
+# Linker in binutils 2.26 and newer consolidates R_X86_64_JUMP_SLOT
+# relocation with R_X86_64_GLOB_DAT relocation against the same symbol.
+libc.so: calloc
+libc.so: free + RELA R_X86_64_GLOB_DAT
+libc.so: malloc + RELA R_X86_64_GLOB_DAT
+libc.so: memalign
+libc.so: realloc
+libm.so: matherr
+# The dynamic loader uses __libc_memalign internally to allocate aligned
+# TLS storage. The other malloc family of functions are expected to allow
+# user symbol interposition.
+ld.so: __libc_memalign
+ld.so: malloc
+ld.so: calloc
+ld.so: realloc
+ld.so: free + RELA R_X86_64_GLOB_DAT
-- 
1.9.3


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] [BZ #18078] FAIL: elf/check-localplt with ld from binutils 2.26
  2015-03-11 17:02   ` H.J. Lu
@ 2015-07-14 19:43     ` H.J. Lu
  2015-07-29 19:06       ` H.J. Lu
  0 siblings, 1 reply; 5+ messages in thread
From: H.J. Lu @ 2015-07-14 19:43 UTC (permalink / raw)
  To: Roland McGrath; +Cc: GNU C Library

On Wed, Mar 11, 2015 at 10:02 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Tue, Mar 10, 2015 at 3:21 PM, Roland McGrath <roland@hack.frob.com> wrote:
>> I don't think this is the way to do it.  For those cases it is mandatory
>> that libc is actually using the PLT entry, so we don't want a check that
>> would pass if libc stopped using it at all.  Perhaps instead there is a way
>> to modify scripts/localplt.awk and/or scripts/check-localplt.awk so that
>> they will grok the new linker's output as constituting use of a PLT entry.
>> Maybe a GLOB_DAT reloc to a symbol that's STT_FUNC is a close enough proxy?
>
> Here is the patch to extend local PLT reference check to support
> alternate relocations.  OK for master?
>
>
> --
> H.J.
> ---
> On x86, linker in binutils 2.26 and newer consolidates R_*_JUMP_SLOT with
> R_*_GLOB_DAT relocation against the same symbol.  This patch extends
> local PLT reference check to support alternate relocations.
>
> [BZ #18078]
> * scripts/check-localplt.awk: Support alternate relocations.
> * scripts/localplt.awk: Also check relocations in DT_RELA/DT_REL
> sections.
> * sysdeps/unix/sysv/linux/i386/localplt.data: Mark free and
> malloc entries with + REL R_386_GLOB_DAT.
> * sysdeps/x86_64/localplt.data: New file.

PING:

https://sourceware.org/ml/libc-alpha/2015-03/msg00456.html

-- 
H.J.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] [BZ #18078] FAIL: elf/check-localplt with ld from binutils 2.26
  2015-07-14 19:43     ` H.J. Lu
@ 2015-07-29 19:06       ` H.J. Lu
  0 siblings, 0 replies; 5+ messages in thread
From: H.J. Lu @ 2015-07-29 19:06 UTC (permalink / raw)
  To: Roland McGrath; +Cc: GNU C Library

On Tue, Jul 14, 2015 at 12:43 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Wed, Mar 11, 2015 at 10:02 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Tue, Mar 10, 2015 at 3:21 PM, Roland McGrath <roland@hack.frob.com> wrote:
>>> I don't think this is the way to do it.  For those cases it is mandatory
>>> that libc is actually using the PLT entry, so we don't want a check that
>>> would pass if libc stopped using it at all.  Perhaps instead there is a way
>>> to modify scripts/localplt.awk and/or scripts/check-localplt.awk so that
>>> they will grok the new linker's output as constituting use of a PLT entry.
>>> Maybe a GLOB_DAT reloc to a symbol that's STT_FUNC is a close enough proxy?
>>
>> Here is the patch to extend local PLT reference check to support
>> alternate relocations.  OK for master?
>>
>>
>> --
>> H.J.
>> ---
>> On x86, linker in binutils 2.26 and newer consolidates R_*_JUMP_SLOT with
>> R_*_GLOB_DAT relocation against the same symbol.  This patch extends
>> local PLT reference check to support alternate relocations.
>>
>> [BZ #18078]
>> * scripts/check-localplt.awk: Support alternate relocations.
>> * scripts/localplt.awk: Also check relocations in DT_RELA/DT_REL
>> sections.
>> * sysdeps/unix/sysv/linux/i386/localplt.data: Mark free and
>> malloc entries with + REL R_386_GLOB_DAT.
>> * sysdeps/x86_64/localplt.data: New file.
>
> PING:
>
> https://sourceware.org/ml/libc-alpha/2015-03/msg00456.html
>

I checked it in.

-- 
H.J.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-07-29 19:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-09 20:26 [PATCH] [BZ #18078] FAIL: elf/check-localplt with ld from binutils 2.26 H.J. Lu
2015-03-10 22:21 ` Roland McGrath
2015-03-11 17:02   ` H.J. Lu
2015-07-14 19:43     ` H.J. Lu
2015-07-29 19:06       ` H.J. Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).