[lld] r305069 - [ELF] - Allow producing -r output if only empty archive is given.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 9 05:26:57 PDT 2017
Author: grimar
Date: Fri Jun 9 07:26:57 2017
New Revision: 305069
URL: http://llvm.org/viewvc/llvm-project?rev=305069&view=rev
Log:
[ELF] - Allow producing -r output if only empty archive is given.
This is used by linux kernel build system.
(https://www.kernel.org/doc/Documentation/kbuild/makefiles.txt "3.2 Built-in object goals")
It has for example next configuration for linking built-in.o files:
drivers-y := $(patsubst %/, %/built-in.o, $(drivers-y))
drivers-$(CONFIG_PCI) += arch/ia64/pci/
...
drivers-$(CONFIG_OPROFILE) += arch/ia64/oprofile/
Im most simple case all CONFIG_* options are off. That means linker is called with empty input archive,
emulation option and no inputs and expected to generate some relocatable output.
ld.bfd is able to do that, we dont.
Patch allows to support this case.
Differential revision: https://reviews.llvm.org/D33937
Added:
lld/trunk/test/ELF/relocatable-empty-archive.s
Modified:
lld/trunk/ELF/Driver.cpp
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=305069&r1=305068&r2=305069&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Fri Jun 9 07:26:57 2017
@@ -185,7 +185,7 @@ void LinkerDriver::addFile(StringRef Pat
// is attempting LTO and using a default ar command that doesn't
// understand the LLVM bitcode file. It is a pretty common error, so
// we'll handle it as if it had a symbol table.
- if (!File->hasSymbolTable()) {
+ if (!File->isEmpty() && !File->hasSymbolTable()) {
for (const auto &P : getArchiveMembers(MBRef))
Files.push_back(make<LazyObjectFile>(P.first, Path, P.second));
return;
Added: lld/trunk/test/ELF/relocatable-empty-archive.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/relocatable-empty-archive.s?rev=305069&view=auto
==============================================================================
--- lld/trunk/test/ELF/relocatable-empty-archive.s (added)
+++ lld/trunk/test/ELF/relocatable-empty-archive.s Fri Jun 9 07:26:57 2017
@@ -0,0 +1,10 @@
+# REQUIRES: x86
+# RUN: rm %t.a
+# RUN: llvm-ar rc %t.a
+# RUN: ld.lld -m elf_x86_64 %t.a -o %t -r
+# RUN: llvm-readobj -file-headers %t | FileCheck %s
+
+# CHECK: Format: ELF64-x86-64
+# CHECK: Arch: x86_64
+# CHECK: AddressSize: 64bit
+# CHECK: Type: Relocatable
More information about the llvm-commits
mailing list