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]

Re: [PATCH] X86-64: Allow copy relocs for building PIE


On Wed, Dec 3, 2014 at 8:13 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Wed, Dec 3, 2014 at 5:44 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Tue, Dec 2, 2014 at 4:59 PM, H.J. Lu <hongjiu.lu@intel.com> wrote:
>>> On Tue, Dec 02, 2014 at 04:53:19PM -0800, H.J. Lu wrote:
>>>> On Tue, Dec 02, 2014 at 03:20:07PM -0800, H.J. Lu wrote:
>>>> > I am checking in this patch to allow copy relocs for non-GOT pc-relative
>>>> > relocation in PIE.  It makes bfd linker compatible with gold.
>>>> >
>>>> >
>>>> > H.J.
>>>> > ----
>>>> > bfd/
>>>> >
>>>> >     * elf64-x86-64.c (elf_x86_64_create_dynamic_sections): Always
>>>> >     allow copy relocs for building executables.
>>>> >     (elf_x86_64_check_relocs): Allow copy relocs for non-GOT
>>>> >     pc-relative relocation in shared object.
>>>> >     (elf_x86_64_adjust_dynamic_symbol): Allocate copy relocs for
>>>> >     PIE.
>>>> >     (elf_x86_64_relocate_section): Don't copy a pc-relative
>>>> >     relocation into the output file if the symbol needs copy reloc.
>>>> >
>>>>
>>>> This patch reverts the change in elf_x86_64_check_relocs and the partial
>>>> change in elf_x86_64_adjust_dynamic_symbol.  Instead, we discard space
>>>> in PIE for relocs against symbols which turn out to need copy relocs.
>>>>
>>>>       * elf64-x86-64.c (elf_x86_64_check_relocs): Revert the last
>>>>       change.
>>>>       (elf_x86_64_adjust_dynamic_symbol): Don't check !info->shared
>>>>       with ELIMINATE_COPY_RELOCS.
>>>>       (elf_x86_64_allocate_dynrelocs): For PIE, discard space for
>>>>       relocs against symbols which turn out to need copy relocs.
>>>> ---
>>>>  bfd/ChangeLog      |  9 +++++++++
>>>>  bfd/elf64-x86-64.c | 36 +++++++++++++++++++++---------------
>>>>  2 files changed, 30 insertions(+), 15 deletions(-)
>>>>
>>>> diff --git a/bfd/ChangeLog b/bfd/ChangeLog
>>>> index 434db31..91245b9 100644
>>>> --- a/bfd/ChangeLog
>>>> +++ b/bfd/ChangeLog
>>>> @@ -1,5 +1,14 @@
>>>>  2014-12-02  H.J. Lu  <hongjiu.lu@intel.com>
>>>>
>>>> +     * elf64-x86-64.c (elf_x86_64_check_relocs): Revert the last
>>>> +     change.
>>>> +     (elf_x86_64_adjust_dynamic_symbol): Don't check !info->shared
>>>> +     with ELIMINATE_COPY_RELOCS.
>>>> +     (elf_x86_64_allocate_dynrelocs): For PIE, discard space for
>>>> +     relocs against symbols which turn out to need copy relocs.
>>>> +
>>>> +2014-12-02  H.J. Lu  <hongjiu.lu@intel.com>
>>>> +
>>>>       * elf64-x86-64.c (elf_x86_64_create_dynamic_sections): Always
>>>>       allow copy relocs for building executables.
>>>>       (elf_x86_64_check_relocs): Allow copy relocs for non-GOT
>>>
>>>
>>> I checked in another small update.
>>>
>>
>> I backported all 3 patches to 2.25 branch.
>
> I also checked this small patch into master and 2.25 branches.
>
> --
> H.J.
> ----
> diff --git a/bfd/ChangeLog b/bfd/ChangeLog
> index f7caed5..61a8b2b 100644
> --- a/bfd/ChangeLog
> +++ b/bfd/ChangeLog
> @@ -1,3 +1,7 @@
> +2014-12-03  H.J. Lu  <hongjiu.lu@intel.com>
> +
> + * elf64-x86-64.c (elf_x86_64_create_dynamic_sections): Reformat.
> +
>  2014-12-02  H.J. Lu  <hongjiu.lu@intel.com>
>

The testcase fails with GCC 4.2.  I checked this patch into
master and 2.25 branch to work around it.


-- 
H.J.
----
commit 1c48ed4fe2f31bf1594164339886dd5d38b5f65e
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Dec 3 08:40:19 2014 -0800

    Replace copyreloc-main.c with copyreloc-main.S

    * ld-x86-64/copyreloc-main.c: Removed.
    * ld-x86-64/copyreloc-main.S: New.
    * ld-x86-64/x86-64.exp: Replace copyreloc-main.c with
    copyreloc-main.S.

diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
index 70201ad..2a06fa0 100644
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2014-12-03  H.J. Lu  <hongjiu.lu@intel.com>
+
+ * ld-x86-64/copyreloc-main.c: Removed.
+ * ld-x86-64/copyreloc-main.S: New.
+ * ld-x86-64/x86-64.exp: Replace copyreloc-main.c with
+ copyreloc-main.S.
+
 2014-12-02  H.J. Lu  <hongjiu.lu@intel.com>

  * ld-x86-64/copyreloc-lib.c: New file.
diff --git a/ld/testsuite/ld-x86-64/copyreloc-main.S
b/ld/testsuite/ld-x86-64/copyreloc-main.S
new file mode 100644
index 0000000..cc17f0e
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/copyreloc-main.S
@@ -0,0 +1,15 @@
+ .section .text.startup,"ax",@progbits
+ .p2align 4,,15
+ .globl main
+ .type main, @function
+main:
+.LFB0:
+ .cfi_startproc
+ xorl %eax, %eax
+ cmpl $2, a_glob(%rip)
+ setne %al
+ ret
+ .cfi_endproc
+.LFE0:
+ .size main, .-main
+ .section .note.GNU-stack,"",@progbits
diff --git a/ld/testsuite/ld-x86-64/copyreloc-main.c
b/ld/testsuite/ld-x86-64/copyreloc-main.c
deleted file mode 100644
index 430eefb..0000000
--- a/ld/testsuite/ld-x86-64/copyreloc-main.c
+++ /dev/null
@@ -1,7 +0,0 @@
-extern int a_glob;
-
-int
-main (void)
-{
-  return a_glob != 2;
-}
diff --git a/ld/testsuite/ld-x86-64/x86-64.exp
b/ld/testsuite/ld-x86-64/x86-64.exp
index 91c9dd9..253f0c6 100644
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -404,7 +404,7 @@ if { [isnative] && [which $CC] != 0 } {
     "Build copyreloc-main with PIE without -fPIE (1)" \
     "tmpdir/copyreloc-lib.so -pie" \
     "" \
-    { copyreloc-main.c } \
+    { copyreloc-main.S } \
     {{readelf {-Wr} copyreloc-main1.rd}} \
     "copyreloc-main" \
  ] \
@@ -412,7 +412,7 @@ if { [isnative] && [which $CC] != 0 } {
     "Build copyreloc-main with PIE without -fPIE (2)" \
     "tmpdir/copyreloc-lib.so -pie" \
     "" \
-    { copyreloc-main.c } \
+    { copyreloc-main.S } \
     {{readelf {-Wr} copyreloc-main2.rd}} \
     "copyreloc-main" \
  ] \
@@ -442,7 +442,7 @@ if { [isnative] && [which $CC] != 0 } {
     "Run copyreloc-main with PIE without -fPIE" \
     "tmpdir/copyreloc-lib.so -pie" \
     "" \
-    { copyreloc-main.c } \
+    { copyreloc-main.S } \
     "copyreloc-main" \
     "copyreloc-main.out" \
  ] \


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