This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Allow producing -r output if only empty archive is given.
ClosedPublic

Authored by grimar on Jun 6 2017, 6:31 AM.

Details

Summary

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.

Diff Detail

Event Timeline

grimar created this revision.Jun 6 2017, 6:31 AM
ruiu added inline comments.Jun 6 2017, 8:43 AM
ELF/Driver.cpp
188

You should check for !File->isEmpty() && !File->hasSymbolTable() here instead of making an non-obvious change to LinkerDriver::createFiles.

test/ELF/Inputs/relocatable-empty-archive.s
1 ↗(On Diff #101551)

This is not an .s file but .a. But you want to avoid checking in an .a file in general. Please create an empty file in the test file using the ar command.

test/ELF/relocatable-empty-archive.s
2

Does this actually create a correct object file? Verify it using objdump.

grimar updated this revision to Diff 101738.Jun 7 2017, 8:03 AM
  • Addressed review comments.
ELF/Driver.cpp
188

Thanks. Done.

grimar planned changes to this revision.Jun 7 2017, 8:38 AM

Planning changes according to Rafael's comments.

grimar updated this revision to Diff 101855.Jun 7 2017, 10:23 PM
  • Updated.
ruiu accepted this revision.Jun 8 2017, 11:07 AM

LGTM

This revision is now accepted and ready to land.Jun 8 2017, 11:07 AM
This revision was automatically updated to reflect the committed changes.