[lld] r282633 - Warn on empty archive files.

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 30 12:35:22 PDT 2016


Say you have a .cc file that looks like

#if defined(OS_LINUX)
void f() {}
#endif

It sounds like it'll still warn on this on non-linux.

(Anyhow, the "have warnings-as-errors, and a toggle for every warning" bit
is more important than the behavior on this specific warning.)

On Fri, Sep 30, 2016 at 3:27 PM, Rui Ueyama <ruiu at google.com> wrote:

> Thank you for the example. With my last commit, LLD now warns on an
> archive file if it has at least one file and has no symbol. So, if an
> archive file is completely empty, it doesn't warn on it. From your example,
> it sounds like the warning message is not going to be spammy.
>
> On Fri, Sep 30, 2016 at 12:25 PM, Nico Weber <thakis at chromium.org> wrote:
>
>> For example
>>
>> static_library("foo") {
>>   if (is_linux) {
>>     sources = [ "foo_linux.cc" ]
>>   } else if (is_win) {
>>     sources = [ "foo_win.cc" ]
>>   }
>> }
>>
>> This is an empty library on mac, android, etc. If static libraries were
>> not allowed, then everything that depends on this would either have to be
>> careful to only depend on "foo" on linux and windows, or each of these
>> libraries would have to be a static_library only on linux and win, and a
>> dummy group elsewhere. We actually did this for a while (due to xcodebuild
>> not liking empty static library targets iirc), and while it's arguably
>> cleaner, it turns out to be annoying to do in practice without any real
>> benefit. So now we have a bunch of these library targets that end up empty
>> on some platforms.
>>
>> On Fri, Sep 30, 2016 at 3:17 PM, Rui Ueyama <ruiu at google.com> wrote:
>>
>>> I'm OK to revert this patch entirely if it is still annoying, but in the
>>> first place why Chromium has an archive file that has no symbols?
>>>
>>> On Fri, Sep 30, 2016 at 12:11 PM, Nico Weber <thakis at chromium.org>
>>> wrote:
>>>
>>>> Also, in case it isn't that way yet, please make sure that for warnings:
>>>>
>>>> 1.) It's possible to turn warnings into errors
>>>> 2.) It's possible to disable every warning with some flag
>>>>
>>>> (like in clang)
>>>>
>>>> For warnings to be enforceable, we need warnings-as-errors. But we
>>>> might not want to fix all the things that a tool warns about, so we need to
>>>> be able to disable warnings we think are useful.
>>>>
>>>> On Fri, Sep 30, 2016 at 1:03 PM, Rui Ueyama <ruiu at google.com> wrote:
>>>>
>>>>> I'd instead make it precise; if an archive file has no symbol table
>>>>> and it contains a LLVM bitcode file, it is likely that the file was created
>>>>> by mistake. What do you think?
>>>>>
>>>>> On Fri, Sep 30, 2016 at 9:58 AM, Nico Weber <thakis at chromium.org>
>>>>> wrote:
>>>>>
>>>>>> libtool (on mac) warns on this, and it's spectacularly unhelpful. We
>>>>>> filter out that warning in a wrapper script since there's no flag to turn
>>>>>> it off and the warning is just noise in our build. If lld gets this
>>>>>> warning, please provide a way to toggle it off.
>>>>>>
>>>>>> On Sep 30, 2016 12:31 PM, "Reid Kleckner" <rnk at google.com> wrote:
>>>>>>
>>>>>>> Are you sure we should be warning on empty archives? This comes up
>>>>>>> in Chromium's build, which apparently has an archive with no symbols:
>>>>>>> https://build.chromium.org/p/chromium.fyi/builders/ClangToTL
>>>>>>> inuxLLD/builds/1596/steps/compile/logs/stdio
>>>>>>>
>>>>>>> That build also doesn't involve LTO, so the long explanatory comment
>>>>>>> isn't helpful.
>>>>>>>
>>>>>>> On Wed, Sep 28, 2016 at 2:10 PM, Rui Ueyama via llvm-commits <
>>>>>>> llvm-commits at lists.llvm.org> wrote:
>>>>>>>
>>>>>>>> Author: ruiu
>>>>>>>> Date: Wed Sep 28 16:10:54 2016
>>>>>>>> New Revision: 282633
>>>>>>>>
>>>>>>>> URL: http://llvm.org/viewvc/llvm-project?rev=282633&view=rev
>>>>>>>> Log:
>>>>>>>> Warn on empty archive files.
>>>>>>>>
>>>>>>>> Differential Revision: https://reviews.llvm.org/D25044
>>>>>>>>
>>>>>>>> Modified:
>>>>>>>>     lld/trunk/ELF/InputFiles.cpp
>>>>>>>>     lld/trunk/test/ELF/empty-archive.s
>>>>>>>>
>>>>>>>> Modified: lld/trunk/ELF/InputFiles.cpp
>>>>>>>> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles
>>>>>>>> .cpp?rev=282633&r1=282632&r2=282633&view=diff
>>>>>>>> ============================================================
>>>>>>>> ==================
>>>>>>>> --- lld/trunk/ELF/InputFiles.cpp (original)
>>>>>>>> +++ lld/trunk/ELF/InputFiles.cpp Wed Sep 28 16:10:54 2016
>>>>>>>> @@ -427,8 +427,17 @@ template <class ELFT> void ArchiveFile::
>>>>>>>>    File = check(Archive::create(MB), "failed to parse archive");
>>>>>>>>
>>>>>>>>    // Read the symbol table to construct Lazy objects.
>>>>>>>> -  for (const Archive::Symbol &Sym : File->symbols())
>>>>>>>> +  bool IsEmpty = true;
>>>>>>>> +  for (const Archive::Symbol &Sym : File->symbols()) {
>>>>>>>>      Symtab<ELFT>::X->addLazyArchive(this, Sym);
>>>>>>>> +    IsEmpty = false;
>>>>>>>> +  }
>>>>>>>> +
>>>>>>>> +  if (IsEmpty)
>>>>>>>> +    warning(getName() + " has no symbol. Chances are you are doing
>>>>>>>> "
>>>>>>>> +            "an LTO build and forgot to use an ar command that can
>>>>>>>> create "
>>>>>>>> +            "a symbol table for LLVM bitcode files. If so, use
>>>>>>>> llvm-ar or "
>>>>>>>> +            "GNU ar + plugin.");
>>>>>>>>  }
>>>>>>>>
>>>>>>>>  // Returns a buffer pointing to a member file containing a given
>>>>>>>> symbol.
>>>>>>>>
>>>>>>>> Modified: lld/trunk/test/ELF/empty-archive.s
>>>>>>>> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/empty
>>>>>>>> -archive.s?rev=282633&r1=282632&r2=282633&view=diff
>>>>>>>> ============================================================
>>>>>>>> ==================
>>>>>>>> --- lld/trunk/test/ELF/empty-archive.s (original)
>>>>>>>> +++ lld/trunk/test/ELF/empty-archive.s Wed Sep 28 16:10:54 2016
>>>>>>>> @@ -1,3 +1,5 @@
>>>>>>>>  // RUN: llvm-ar rc %t.a
>>>>>>>>  // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
>>>>>>>> -// RUN: ld.lld -shared %t.o %t.a -o t
>>>>>>>> +// RUN: ld.lld -shared %t.o %t.a -o t 2>&1 | FileCheck %s
>>>>>>>> +
>>>>>>>> +// CHECK: has no symbol.
>>>>>>>>
>>>>>>>>
>>>>>>>> _______________________________________________
>>>>>>>> llvm-commits mailing list
>>>>>>>> llvm-commits at lists.llvm.org
>>>>>>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>
>>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160930/6ca4c5d9/attachment.html>


More information about the llvm-commits mailing list