aboutsummaryrefslogtreecommitdiff
path: root/ld/testsuite
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2018-12-06 11:45:41 -0800
committerH.J. Lu <hjl.tools@gmail.com>2024-03-26 07:17:17 -0700
commitbb9a951fab7a30cc1209c6b8b1716c13456e8b1a (patch)
treec3defd5dc0641dbcd0872ea9b5a738bff9262a2d /ld/testsuite
parentf4c19f89ef43dbce8065532c808e1aeb05d08994 (diff)
downloadgdb-bb9a951fab7a30cc1209c6b8b1716c13456e8b1a.zip
gdb-bb9a951fab7a30cc1209c6b8b1716c13456e8b1a.tar.gz
gdb-bb9a951fab7a30cc1209c6b8b1716c13456e8b1a.tar.bz2
Don't claim a fat IR object if no IR object should be claimed
When the linker sees an input object containing nothing but IR during rescan, it should ignore it (LTO phase is over). But if the input object is a fat IR object, which has non-IR code as well, it should be used to resolve references as if it did not contain any IR at all. This patch adds lto_type to bfd and linker avoids claiming a fat IR object if no IR object should be claimed. bfd/ PR ld/23935 * archive.c (_bfd_compute_and_write_armap): Check bfd_get_lto_type instead of lto_slim_object. * elflink.c (elf_link_add_object_symbols): Likewise. * bfd.c (bfd_lto_object_type): New. (bfd): Remove lto_slim_object and add lto_type. (bfd_get_lto_type): New function. * elf.c (lto_section): Removed. (_bfd_elf_make_section_from_shdr): Don't set lto_slim_object. * format.c: (lto_section): New. (bfd_set_lto_type): New function. (bfd_check_format_matches): Call bfd_set_lto_type. * bfd-in2.h: Regenerated. binutils/ PR ld/23935 * nm.c (display_rel_file): Check bfd_get_lto_type instead of lto_slim_object. ld/ PR ld/23935 * ldmain.c (add_archive_element): Don't claim a fat IR object if no IR object should be claimed. * testsuite/ld-plugin/lto.exp (pr20103): Adjust fat IR test. Add PR ld/23935 test. * testsuite/ld-plugin/pr23935a.c: New file. * testsuite/ld-plugin/pr23935b.c: Likewise.
Diffstat (limited to 'ld/testsuite')
-rw-r--r--ld/testsuite/ld-plugin/lto.exp35
-rw-r--r--ld/testsuite/ld-plugin/pr23935a.c2
-rw-r--r--ld/testsuite/ld-plugin/pr23935b.c2
3 files changed, 37 insertions, 2 deletions
diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index cf1691f..259a064 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -964,10 +964,20 @@ proc pr20103 {cflags libs} {
set testname "PR ld/20103 ($cflags $libs)"
set exec_output [run_host_cmd "$CC_FOR_TARGET" "$cflags $libs"]
+ # NB: Starting from GCC 4.9, -flto is optional for final link.
+ if { [ regexp "fatpr20103" "$libs" ] \
+ && ([regexp " -flto" "$cflags"] \
+ || [at_least_gcc_version 4 9]) } {
+ set result1good "fail"
+ set result1bad "pass"
+ } {
+ set result1good "pass"
+ set result1bad "fail"
+ }
if { [ regexp "undefined reference to `\\.?dead'" $exec_output ] } {
- pass "$testname (1)"
+ $result1good "$testname (1)"
} {
- fail "$testname (1)"
+ $result1bad "$testname (1)"
}
if { [ regexp "plugin needed to handle lto object" $exec_output ] } {
fail "$testname (2)"
@@ -1026,6 +1036,27 @@ if { [check_lto_fat_available] } {
"-O2" \
{dummy.c} {} "pr20103c" \
] \
+ [list "Build fatpr23935.a" \
+ "$plug_opt" \
+ "-flto -fno-builtin -ffat-lto-objects" \
+ {pr23935a.c} \
+ "" \
+ "fatpr23935.a" \
+ ] \
+ [list "Build pr23935b.o" \
+ "$plug_opt" \
+ "-flto -fno-fat-lto-objects" \
+ {pr23935b.c} \
+ ] \
+ [list \
+ "Build pr23935" \
+ "-static -flto -Wl,-emain -nostdlib tmpdir/pr23935b.o \
+ tmpdir/fatpr23935.a" \
+ "-flto -fno-fat-lto-objects" \
+ {dummy.c} \
+ "" \
+ "pr23935" \
+ ] \
]
pr20103 "-O2 -flto" "tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a"
pr20103 "-O2 -flto" "tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a"
diff --git a/ld/testsuite/ld-plugin/pr23935a.c b/ld/testsuite/ld-plugin/pr23935a.c
new file mode 100644
index 0000000..8c73197
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr23935a.c
@@ -0,0 +1,2 @@
+#include <stdio.h>
+int puts(const char *s) { return 0; }
diff --git a/ld/testsuite/ld-plugin/pr23935b.c b/ld/testsuite/ld-plugin/pr23935b.c
new file mode 100644
index 0000000..58ae07e
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr23935b.c
@@ -0,0 +1,2 @@
+#include <stdio.h>
+int main() { printf("hi\n"); return 0; }