This is an archive of the discontinued LLVM Phabricator instance.

Reject .so files if -static is given.
ClosedPublic

Authored by ruiu on Dec 18 2018, 11:39 AM.

Details

Summary

Previously, if you pass -static to lld, lld searches for only foo.a
and skips foo.so for -lfoo option. However, it didn't reject .so files
if you directly pass their pathnames via the command line, which is a bug.

Event Timeline

ruiu created this revision.Dec 18 2018, 11:39 AM

LG, but not sure if the comment should mention -static. I think bfd's comment is better

https://sourceware.org/git/?p=binutils-gdb.git;a=blob;hb=2d5d5a8f0a8b5a03454bf168b7fa7024bb1ebbd8;f=ld/ldfile.c#l276

% ld.bfd t.o -static t.so
ld.bfd: attempted static link of dynamic object `t.so'

In gold, -static is a separate state, different from -Bdynamic/-Bstatic.

  if (!doing_static_link && options.is_static())
    {
      // We print out just the first .so we see; there may be others.
      gold_assert(input_objects->dynobj_begin() != input_objects->dynobj_end());
      gold_error(_("cannot mix -static with dynamic object %s"),
		 (*input_objects->dynobj_begin())->name().c_str());
    }
% gold t.o -static t.so
gold: error: cannot mix -static with dynamic object t.so
lld/test/ELF/static-error.s
8

POSIX sh does not support >& (but supports >&fd)

You may use 2>&1 >/dev/null | FileCheck if you want to emphasize stderr is checked.

ruiu updated this revision to Diff 178770.Dec 18 2018, 12:59 PM
  • Review comments.
ruiu updated this revision to Diff 178771.Dec 18 2018, 1:00 PM
  • Fix typo
ruiu marked an inline comment as done.Dec 18 2018, 1:02 PM
ruiu added inline comments.
lld/test/ELF/static-error.s
8

Even thought lit tests support features such as redirection that you can find in Unix shells, these RUN commands are not run on a Unix shell, so it is safe to use >& as long as it works on lit.

MaskRay accepted this revision.Dec 18 2018, 1:08 PM
MaskRay added inline comments.
lld/test/ELF/static-error.s
8

2>&1 | FileCheck LG.

This revision is now accepted and ready to land.Dec 18 2018, 1:08 PM
MaskRay added inline comments.Dec 18 2018, 1:16 PM
lld/test/ELF/static-error.s
8

I don't know how lit runs the script.

On my machine, after running the test, I get a script:
llvm/$build/projects/lld/test/ELF/Output/aarch64-abs16.s.script

I can run that script with my $SHELL (zsh, but it may be sh for some people), so the POSIX shell compatibility is good.

This revision was automatically updated to reflect the committed changes.