example some @code{a.out}-based formats do not support partial linking
with input files in other formats at all.
-On ELF platforms, when the relocatable output contains both contents
-which require link-time optimization (LTO) and contents which don't
-require LTO, a .gnu_object_only section will be created to contain a
-relocatable object file, as if @samp{-r} is applied to all relocatable
-inputs which don't require LTO. When processing a relocatable input
-with a .gnu_object_only section, the linker will extract the
-.gnu_object_only section as a separate input.
+When the relocatable output contains both contents which require
+link-time optimization (LTO) and contents which don't require LTO,
+a .gnu_object_only section will be created to contain a relocatable
+object file, as if @samp{-r} is applied to all relocatable inputs
+which don't require LTO. When processing a relocatable input with
+a .gnu_object_only section, the linker will extract the .gnu_object_only
+section as a separate input.
Note that since @samp{-r} groups some sections from different input files
together, there may be negative impacts on code size and locality in
return name;
}
+/* Load the object-only section. */
+
+static void
+cmdline_load_object_only_section (const char *name)
+{
+ lang_input_statement_type *entry
+ = new_afile (name, lang_input_file_is_file_enum, NULL, NULL);
+
+ if (!entry)
+ abort ();
+
+ ldfile_open_file (entry);
+
+ if (trace_files || verbose)
+ info_msg ("%pI\n", entry);
+
+ if (entry->flags.missing_file
+ || bfd_get_format (entry->the_bfd) != bfd_object)
+ abort ();
+
+ ldlang_add_file (entry);
+
+ if (bfd_link_add_symbols (entry->the_bfd, &link_info))
+ entry->flags.loaded = true;
+ else
+ einfo (_("%F%P: %pB: error adding symbols: %E\n"), entry->the_bfd);
+}
+
/* Check and handle the object-only section. */
void
abort ();
case lto_mixed_object:
filename = cmdline_extract_object_only_section (abfd);
- lang_add_input_file (filename,
- lang_input_file_is_file_enum, NULL);
+ cmdline_load_object_only_section (filename);
break;
case lto_non_ir_object:
case lto_slim_ir_object:
[list "LTO 3c" \
"-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o -Wl,--whole-archive tmpdir/liblto-3.a -Wl,--no-whole-archive tmpdir/liblto-3.a" "" \
{dummy.c} "lto-3d.exe" "lto-3.out" "" "c"] \
+ [list "LTO 4a" \
+ "-O2 -flto -fuse-linker-plugin \
+ -Wl,--no-warn-execstack,--no-error-execstack \
+ tmpdir/lto-4r-a.o" "" \
+ {dummy.c} "lto-4a.exe" "lto-4.out" "" "c"] \
+ [list "LTO 4c" \
+ "-O2 -flto -fuse-linker-plugin \
+ -Wl,--no-warn-execstack,--no-error-execstack \
+ tmpdir/lto-4r-c.o" "" \
+ {dummy.c} "lto-4c.exe" "lto-4.out" "" "c"] \
+ [list "LTO 4d" \
+ "-O2 -flto -fuse-linker-plugin \
+ -Wl,--no-warn-execstack,--no-error-execstack \
+ tmpdir/lto-4r-d.o" "" \
+ {dummy.c} "lto-4d.exe" "lto-4.out" "" "c"] \
[list "LTO 5" \
"-O2 -flto -fuse-linker-plugin tmpdir/lto-5.o" "" \
{dummy.c} "lto-5.exe" "lto-5.out" "" "c"] \
+ [list "LTO 10" \
+ "-O2 -flto -fuse-linker-plugin \
+ -Wl,--no-warn-execstack,--no-error-execstack \
+ tmpdir/lto-10.o" "" \
+ {dummy.c} "lto-10.exe" "lto-10.out" "" "c"] \
[list "LTO 11" \
"-O -flto -fuse-linker-plugin tmpdir/liblto-11.a" "" \
{dummy.c} "lto-11.exe" "lto-11.out" "" "c"] \
# LTO run-time tests for ELF
set lto_run_elf_tests [list \
- [list "LTO 4a" \
- "-O2 -flto -fuse-linker-plugin \
- -Wl,--no-warn-execstack,--no-error-execstack \
- tmpdir/lto-4r-a.o" "" \
- {dummy.c} "lto-4a.exe" "lto-4.out" "" "c"] \
- [list "LTO 4c" \
- "-O2 -flto -fuse-linker-plugin \
- -Wl,--no-warn-execstack,--no-error-execstack \
- tmpdir/lto-4r-c.o" "" \
- {dummy.c} "lto-4c.exe" "lto-4.out" "" "c"] \
- [list "LTO 4d" \
- "-O2 -flto -fuse-linker-plugin \
- -Wl,--no-warn-execstack,--no-error-execstack \
- tmpdir/lto-4r-d.o" "" \
- {dummy.c} "lto-4d.exe" "lto-4.out" "" "c"] \
[list "LTO 8" \
"-O2 -flto -fuse-linker-plugin tmpdir/lto-8b.o tmpdir/lto-8a.o" "" \
{dummy.c} "lto-8.exe" "lto-8.out" "" "c"] \
- [list "LTO 10" \
- "-O2 -flto -fuse-linker-plugin \
- -Wl,--no-warn-execstack,--no-error-execstack \
- tmpdir/lto-10.o" "" \
- {dummy.c} "lto-10.exe" "lto-10.out" "" "c"] \
[list "LTO TLS IE" \
"-O2 -flto -fuse-linker-plugin" "" \
{run-ie.c} "run-ie.exe" "run-ie.out" "" "c"] \
# Run "ld -r" to generate inputs for complex LTO tests.
run_dump_test "lto-3r"
remote_exec host "mv" "tmpdir/dump tmpdir/lto-3.o"
+run_dump_test "lto-4r-a"
+remote_exec host "mv" "tmpdir/dump tmpdir/lto-4r-a.o"
+run_dump_test "lto-4r-b"
+remote_exec host "mv" "tmpdir/dump tmpdir/lto-4r-b.o"
+run_dump_test "lto-4r-c"
+remote_exec host "mv" "tmpdir/dump tmpdir/lto-4r-c.o"
+run_dump_test "lto-4r-d"
+remote_exec host "mv" "tmpdir/dump tmpdir/lto-4r-d.o"
run_dump_test "lto-5r"
remote_exec host "mv" "tmpdir/dump tmpdir/lto-5.o"
-if { [is_elf_format] } {
- run_dump_test "lto-4r-a"
- remote_exec host "mv" "tmpdir/dump tmpdir/lto-4r-a.o"
- run_dump_test "lto-4r-b"
- remote_exec host "mv" "tmpdir/dump tmpdir/lto-4r-b.o"
- run_dump_test "lto-4r-c"
- remote_exec host "mv" "tmpdir/dump tmpdir/lto-4r-c.o"
- run_dump_test "lto-4r-d"
- remote_exec host "mv" "tmpdir/dump tmpdir/lto-4r-d.o"
- run_dump_test "lto-10r"
- remote_exec host "mv" "tmpdir/dump tmpdir/lto-10.o"
- set testname "nm mixed object"
- set lto_plugin [string trim [run_host_cmd "$CC_FOR_TARGET" "-print-prog-name=liblto_plugin.so"]]
- if { [ regexp "liblto_plugin.so" $lto_plugin ] } {
- set exec_output [run_host_cmd "$NM" "--plugin $lto_plugin tmpdir/lto-10.o"]
- if { [ regexp "(D|T) main" $exec_output ] } {
- pass $testname
- } else {
- fail $testname
- }
+run_dump_test "lto-10r"
+remote_exec host "mv" "tmpdir/dump tmpdir/lto-10.o"
+set testname "nm mixed object"
+set lto_plugin [string trim [run_host_cmd "$CC_FOR_TARGET" "-print-prog-name=liblto_plugin.so"]]
+if { [ regexp "liblto_plugin.so" $lto_plugin ] } {
+ set exec_output [run_host_cmd "$NM" "--plugin $lto_plugin tmpdir/lto-10.o"]
+ if { [ regexp "(D|T) main" $exec_output ] } {
+ pass $testname
} else {
fail $testname
}
+} else {
+ fail $testname
}
run_cc_link_tests $lto_link_symbol_tests