Bug 24151 - Regression about copy relocation of protected data
Summary: Regression about copy relocation of protected data
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.31
: P2 normal
Target Milestone: 2.33
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 24218 (view as bug list)
Depends on: 22791
Blocks:
  Show dependency treegraph
 
Reported: 2019-01-31 07:33 UTC by Robin Lee
Modified: 2019-02-13 14:50 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2019-02-06 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Robin Lee 2019-01-31 07:33:55 UTC
clang(7.0.1) does not build correct code for copy relocation of protected data. And ld.bfd of 2.30 will refuse to link the shared object. But ld.bfd 2.31.1 will not.

I run the test program posted on
https://bugs.llvm.org/show_bug.cgi?id=26580#c0

With binutils 2.30:

clang  -O3 -c -o x.o x.c
clang  -O3 -fpic    -c -o bar.o bar.c
clang  -fuse-ld=bfd -shared -o libfoo.so bar.o
/usr/bin/ld.bfd: bar.o: relocation R_X86_64_PC32 against protected symbol `a' can not be used when making a shared object
/usr/bin/ld.bfd: final link failed: Bad value
clang-7: error: linker command failed with exit code 1 (use -v to see invocation)

With binutils 2.31.1, linking is completed with no error/warning.
Comment 1 Sourceware Commits 2019-02-06 02:46:37 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=83924b3846361f2f76f9a6e7b5afa01c0eebbd4f

commit 83924b3846361f2f76f9a6e7b5afa01c0eebbd4f
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Tue Feb 5 18:45:23 2019 -0800

    x86-64: Restore PIC check for PCREL reloc against protected symbol
    
    commit bd7ab16b4537788ad53521c45469a1bdae84ad4a
    Author: H.J. Lu <hjl.tools@gmail.com>
    Date:   Tue Feb 13 07:34:22 2018 -0800
    
        x86-64: Generate branch with PLT32 relocation
    
    removed check R_X86_64_PC32 relocation against protected symbols in
    shared objects.  Since elf_x86_64_check_relocs is called after we
    have seen all input files, we can check for PC-relative relocations in
    elf_x86_64_check_relocs.  We should not allow PC-relative relocations
    against protected symbols since address of protected function and
    location of protected data may not be in the shared object.
    
    bfd/
    
    	PR ld/24151
    	* elf64-x86-64.c (elf_x86_64_need_pic): Check
    	SYMBOL_DEFINED_NON_SHARED_P instead of def_regular.
    	(elf_x86_64_relocate_section): Move PIC check for PC-relative
    	relocations to ...
    	(elf_x86_64_check_relocs): Here.
    	(elf_x86_64_finish_dynamic_symbol): Use SYMBOL_DEFINED_NON_SHARED_P
    	to check if a symbol is defined in a non-shared object.
    	* elfxx-x86.h (SYMBOL_DEFINED_NON_SHARED_P): New.
    
    ld/
    
    	PR ld/24151
    	* testsuite/ld-x86-64/pr24151a-x32.d: New file.
    	* testsuite/ld-x86-64/pr24151a.d: Likewise.
    	* testsuite/ld-x86-64/pr24151a.s: Likewise.
    	* testsuite/ld-x86-64/x86-64.exp: Run pr24151a and pr24151a-x32.
Comment 2 H.J. Lu 2019-02-06 02:50:33 UTC
Fixed for 2.33 so far.
Comment 3 Sourceware Commits 2019-02-10 12:55:57 UTC
The binutils-2_32-branch branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=db949bdcfb536f09b70cd7f57371c96042c4f216

commit db949bdcfb536f09b70cd7f57371c96042c4f216
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Tue Feb 5 18:45:23 2019 -0800

    x86-64: Restore PIC check for PCREL reloc against protected symbol
    
    commit bd7ab16b4537788ad53521c45469a1bdae84ad4a
    Author: H.J. Lu <hjl.tools@gmail.com>
    Date:   Tue Feb 13 07:34:22 2018 -0800
    
        x86-64: Generate branch with PLT32 relocation
    
    removed check R_X86_64_PC32 relocation against protected symbols in
    shared objects.  Since elf_x86_64_check_relocs is called after we
    have seen all input files, we can check for PC-relative relocations in
    elf_x86_64_check_relocs.  We should not allow PC-relative relocations
    against protected symbols since address of protected function and
    location of protected data may not be in the shared object.
    
    bfd/
    
    	PR ld/24151
    	* elf64-x86-64.c (elf_x86_64_need_pic): Check
    	SYMBOL_DEFINED_NON_SHARED_P instead of def_regular.
    	(elf_x86_64_relocate_section): Move PIC check for PC-relative
    	relocations to ...
    	(elf_x86_64_check_relocs): Here.
    	(elf_x86_64_finish_dynamic_symbol): Use SYMBOL_DEFINED_NON_SHARED_P
    	to check if a symbol is defined in a non-shared object.
    	* elfxx-x86.h (SYMBOL_DEFINED_NON_SHARED_P): New.
    
    ld/
    
    	PR ld/24151
    	* testsuite/ld-x86-64/pr24151a-x32.d: New file.
    	* testsuite/ld-x86-64/pr24151a.d: Likewise.
    	* testsuite/ld-x86-64/pr24151a.s: Likewise.
    	* testsuite/ld-x86-64/x86-64.exp: Run pr24151a and pr24151a-x32.
    
    (cherry picked from commit 83924b3846361f2f76f9a6e7b5afa01c0eebbd4f)
Comment 4 Sourceware Commits 2019-02-10 13:52:47 UTC
The binutils-2_31-branch branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=c83ac8021a7649c148cb344870d8ce711eecc3c6

commit c83ac8021a7649c148cb344870d8ce711eecc3c6
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Tue Feb 5 18:45:23 2019 -0800

    x86-64: Restore PIC check for PCREL reloc against protected symbol
    
    commit bd7ab16b4537788ad53521c45469a1bdae84ad4a
    Author: H.J. Lu <hjl.tools@gmail.com>
    Date:   Tue Feb 13 07:34:22 2018 -0800
    
        x86-64: Generate branch with PLT32 relocation
    
    removed check R_X86_64_PC32 relocation against protected symbols in
    shared objects.  Since elf_x86_64_check_relocs is called after we
    have seen all input files, we can check for PC-relative relocations in
    elf_x86_64_check_relocs.  We should not allow PC-relative relocations
    against protected symbols since address of protected function and
    location of protected data may not be in the shared object.
    
    bfd/
    
    	PR ld/24151
    	* elf64-x86-64.c (elf_x86_64_need_pic): Check
    	SYMBOL_DEFINED_NON_SHARED_P instead of def_regular.
    	(elf_x86_64_relocate_section): Move PIC check for PC-relative
    	relocations to ...
    	(elf_x86_64_check_relocs): Here.
    	(elf_x86_64_finish_dynamic_symbol): Use SYMBOL_DEFINED_NON_SHARED_P
    	to check if a symbol is defined in a non-shared object.
    	* elfxx-x86.h (SYMBOL_DEFINED_NON_SHARED_P): New.
    
    ld/
    
    	PR ld/24151
    	* testsuite/ld-x86-64/pr24151a-x32.d: New file.
    	* testsuite/ld-x86-64/pr24151a.d: Likewise.
    	* testsuite/ld-x86-64/pr24151a.s: Likewise.
    	* testsuite/ld-x86-64/x86-64.exp: Run pr24151a and pr24151a-x32.
    
    (cherry picked from commit 83924b3846361f2f76f9a6e7b5afa01c0eebbd4f)
Comment 5 H.J. Lu 2019-02-10 14:17:50 UTC
Fixed for 2.33 and on 2.31/2.32 branches.
Comment 6 H.J. Lu 2019-02-13 14:50:05 UTC
*** Bug 24218 has been marked as a duplicate of this bug. ***