This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH] ELF: Don't check DT_NEEDED for linker script defined symbols
On Tue, Nov 28, 2017 at 5:04 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Tue, Nov 28, 2017 at 4:26 AM, Alan Modra <amodra@gmail.com> wrote:
>> On Mon, Nov 27, 2017 at 02:55:55PM +1030, Alan Modra wrote:
>>> On Mon, Nov 27, 2017 at 07:12:59AM +1030, Alan Modra wrote:
>>> > We already process some assignments in open_input_bfds to have
>>> > --defsym symbols defined early, so (3) shouldn't be too hard.
>>>
>>> I'm testing the following.
>>
>> Well, that failed badly on mmix use of DEFINED. I'd missed the need
>> to increment lang_statement_iteration before open_input_bfds, and with
>> DEFINED not returning values on the first pass ld could trash symbols
>> defined in object files. It's also possible for update_definedness to
>> be missed on one pass, hence the need to track more than one bit of
>> lang_statement_iteration.
>>
>>
>> This patch processes linker script assignment statements before ld
>> opens DT_NEEDED libraries, in order to define symbols like __bss_start
>> that might also be defined by a library, falsely triggering an error
>> about "DSO missing from command line".
>>
>> The initial value won't be correct when assigning a symbol from dot,
>> and I make no attempt to handle all expressions. For example, an
>> assignment like "_start_foo = ADDR (.foo)" isn't valid until sections
>> are laid out, so won't define _start_foo early. What's here should be
>> enough for most common scripts, and hopefully won't perturb fragile
>> scripts.
>>
>> bfd/
>> PR 22471
>> * elflink.c (_bfd_elf_merge_symbol): Allow weak symbols to override
>> early passes over linker script symbols.
>> * linker.c (_bfd_generic_link_add_one_symbol): Allow symbols to
>> override early passes over linker script symbols. Clear ldscript_def
>> on symbol definitions.
>> ld/
>> PR 22471
>> * ldexp.c (struct definedness_hash_entry): Delete "by_script". Make
>> "iteration" an 8-bit field, and update mask in all uses.
>> (definedness_newfunc): Don't init "by_script".
>> (update_definedness): Test ldscript_def rather than by_script.
>> (is_sym_value): Likewise.
>> (fold_name <DEFINED>): Return a result for first phase. Test
>> ldscript_def.
>> (fold_name <NAME>): Return a result for first phase.
>> * ldlang.c (open_input_bfds): Process all assignments, not just
>> defsym.
>> (lang_process): Increment lang_statement_iteration before
>> open_input_bfds.
>> * testsuite/ld-mips-elf/tlsdyn-o32-1.d: Adjust for larger .dynsym.
>> * testsuite/ld-mips-elf/tlsdyn-o32-1.got: Likewise.
>> * testsuite/ld-mips-elf/tlsdyn-o32-2.d: Likewise.
>> * testsuite/ld-mips-elf/tlsdyn-o32-2.got: Likewise.
>> * testsuite/ld-mips-elf/tlsdyn-o32-3.d: Likewise.
>> * testsuite/ld-mips-elf/tlsdyn-o32-3.got: Likewise.
>>
>
> Here is a patch to add a testcase. OK for master?
>
> Thanks.
>
>
> --
> H.J.
> ---
> From 7ce00e7a68138f6d58d9d7db8a096dad24b8e47e Mon Sep 17 00:00:00 2001
> From: "H.J. Lu" <hjl.tools@gmail.com>
> Date: Thu, 23 Nov 2017 08:36:21 -0800
> Subject: [PATCH] ld: Add a testcase for PR ld/22471
>
> PR ld/22471
> * testsuite/ld-elf/pr22471.t: New file.
> * testsuite/ld-elf/pr22471a.s: Likewise.
> * testsuite/ld-elf/pr22471b.s: Likewise.
> * testsuite/ld-elf/shared.exp (ASFLAGS): Define UNDERSCORE for
> underscore targets.
> Run PR ld/22471 tests.
Resent as an attachment. I will check it tomorrow if there are no objections.
--
H.J.
From 7ce00e7a68138f6d58d9d7db8a096dad24b8e47e Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Thu, 23 Nov 2017 08:36:21 -0800
Subject: [PATCH] ld: Add a testcase for PR ld/22471
PR ld/22471
* testsuite/ld-elf/pr22471.t: New file.
* testsuite/ld-elf/pr22471a.s: Likewise.
* testsuite/ld-elf/pr22471b.s: Likewise.
* testsuite/ld-elf/shared.exp (ASFLAGS): Define UNDERSCORE for
underscore targets.
Run PR ld/22471 tests.
---
ld/testsuite/ld-elf/pr22471.t | 1 +
ld/testsuite/ld-elf/pr22471a.s | 1 +
ld/testsuite/ld-elf/pr22471b.s | 17 +++++++++++++++++
ld/testsuite/ld-elf/shared.exp | 34 ++++++++++++++++++++++++++++++++++
4 files changed, 53 insertions(+)
create mode 100644 ld/testsuite/ld-elf/pr22471.t
create mode 100644 ld/testsuite/ld-elf/pr22471a.s
create mode 100644 ld/testsuite/ld-elf/pr22471b.s
diff --git a/ld/testsuite/ld-elf/pr22471.t b/ld/testsuite/ld-elf/pr22471.t
new file mode 100644
index 0000000000..8862dc291d
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr22471.t
@@ -0,0 +1 @@
+{ local: *; };
diff --git a/ld/testsuite/ld-elf/pr22471a.s b/ld/testsuite/ld-elf/pr22471a.s
new file mode 100644
index 0000000000..3bb6a92bdb
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr22471a.s
@@ -0,0 +1 @@
+# Empty input.
diff --git a/ld/testsuite/ld-elf/pr22471b.s b/ld/testsuite/ld-elf/pr22471b.s
new file mode 100644
index 0000000000..f4edad0464
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr22471b.s
@@ -0,0 +1,17 @@
+ .type start,"function"
+ .global start
+start:
+ .type _start,"function"
+ .global _start
+_start:
+ .type __start,"function"
+ .global __start
+__start:
+ .type main,"function"
+ .global main
+main:
+ .ifdef UNDERSCORE
+ .dc.a ___bss_start
+ .else
+ .dc.a __bss_start
+ .endif
diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp
index a40f8e0f59..7514eb116b 100644
--- a/ld/testsuite/ld-elf/shared.exp
+++ b/ld/testsuite/ld-elf/shared.exp
@@ -47,6 +47,40 @@ if [istarget "tic6x-*-*"] {
append LFLAGS " -melf32_tic6x_le"
}
+if [is_underscore_target] {
+ set ASFLAGS "$ASFLAGS --defsym UNDERSCORE=1"
+}
+
+run_ld_link_tests [list \
+ [list \
+ "Build pr22471a.so" \
+ "$LFLAGS -shared" \
+ "" \
+ "$AFLAGS_PIC" \
+ {pr22471a.s} \
+ {} \
+ "pr22471a.so" \
+ ] \
+ [list \
+ "Build pr22471b.so" \
+ "$LFLAGS -shared --version-script pr22471.t" \
+ "tmpdir/pr22471a.so" \
+ "$AFLAGS_PIC" \
+ {pr22471a.s} \
+ {} \
+ "pr22471b.so" \
+ ] \
+ [list \
+ "Build pr22471" \
+ "$LFLAGS -rpath-link ." \
+ "tmpdir/pr22471b.so" \
+ "" \
+ {pr22471b.s} \
+ {} \
+ "pr22471" \
+ ] \
+]
+
# PR ld/20828 check for correct dynamic symbol table entries where:
# - symbols have been defined with a linker script,
# - the same symbols have been seen in shared library used in the link,
--
2.14.3