[PATCH] D33937: [ELF] - Allow producing -r output if only empty archive is given.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 6 06:31:05 PDT 2017


grimar created this revision.
Herald added subscribers: mehdi_amini, emaste.

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_IA64_HP_SIM)	+= arch/ia64/hp/sim/
  drivers-$(CONFIG_IA64_HP_ZX1)	+= arch/ia64/hp/common/ arch/ia64/hp/zx1/
  drivers-$(CONFIG_IA64_HP_ZX1_SWIOTLB) += arch/ia64/hp/common/ arch/ia64/hp/zx1/
  drivers-$(CONFIG_IA64_GENERIC)	+= arch/ia64/hp/common/ arch/ia64/hp/zx1/ arch/ia64/hp/sim/ arch/ia64/sn/ arch/ia64/uv/
  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, because execution falls into following code
and Files remains empty:

  // If an archive file has no symbol table, it is likely that a user
  // 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()) {
    for (const auto &P : getArchiveMembers(MBRef))
      Files.push_back(make<LazyObjectFile>(P.first, Path, P.second));
    return;
  }

I suggest as a simple solution just to allow -r with no inputs to allow producing empty relocatable output here.


https://reviews.llvm.org/D33937

Files:
  ELF/Driver.cpp
  test/ELF/Inputs/relocatable-empty-archive.s
  test/ELF/relocatable-empty-archive.s


Index: test/ELF/relocatable-empty-archive.s
===================================================================
--- test/ELF/relocatable-empty-archive.s
+++ test/ELF/relocatable-empty-archive.s
@@ -0,0 +1 @@
+# RUN: ld.lld -m elf_x86_64 %S/Inputs/relocatable-empty-archive.s -o %t -r
Index: test/ELF/Inputs/relocatable-empty-archive.s
===================================================================
--- test/ELF/Inputs/relocatable-empty-archive.s
+++ test/ELF/Inputs/relocatable-empty-archive.s
@@ -0,0 +1 @@
+!<arch>
Index: ELF/Driver.cpp
===================================================================
--- ELF/Driver.cpp
+++ ELF/Driver.cpp
@@ -849,7 +849,7 @@
     }
   }
 
-  if (Files.empty() && ErrorCount == 0)
+  if ((!Config->Relocatable && Files.empty()) && ErrorCount == 0)
     error("no input files");
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33937.101551.patch
Type: text/x-patch
Size: 827 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170606/4d518482/attachment.bin>


More information about the llvm-commits mailing list