<div dir="ltr">Say you have a .cc file that looks like<div><br></div><div>#if defined(OS_LINUX)</div><div>void f() {}</div><div>#endif</div><div><br></div><div>It sounds like it'll still warn on this on non-linux.</div><div><br></div><div>(Anyhow, the "have warnings-as-errors, and a toggle for every warning" bit is more important than the behavior on this specific warning.)</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 30, 2016 at 3:27 PM, Rui Ueyama <span dir="ltr"><<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">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.</div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 30, 2016 at 12:25 PM, Nico Weber <span dir="ltr"><<a href="mailto:thakis@chromium.org" target="_blank">thakis@chromium.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">For example<div><br></div><div>static_library("foo") {</div><div> if (is_linux) {</div><div> sources = [ "foo_linux.cc" ]</div><div> } else if (is_win) {</div><div> sources = [ "foo_win.cc" ]</div><div> }</div><div>}</div><div><br></div><div>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.</div></div><div class="m_1823733926161877260HOEnZb"><div class="m_1823733926161877260h5"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 30, 2016 at 3:17 PM, Rui Ueyama <span dir="ltr"><<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">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?</div><div class="m_1823733926161877260m_115211283745012700HOEnZb"><div class="m_1823733926161877260m_115211283745012700h5"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 30, 2016 at 12:11 PM, Nico Weber <span dir="ltr"><<a href="mailto:thakis@chromium.org" target="_blank">thakis@chromium.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra">Also, in case it isn't that way yet, please make sure that for warnings:</div><div class="gmail_extra"><br></div><div class="gmail_extra">1.) It's possible to turn warnings into errors</div><div class="gmail_extra">2.) It's possible to disable every warning with some flag</div><div class="gmail_extra"><br></div><div class="gmail_extra">(like in clang)</div><div class="gmail_extra"><br>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.</div><div><div class="m_1823733926161877260m_115211283745012700m_9094592728340752532h5"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 30, 2016 at 1:03 PM, Rui Ueyama <span dir="ltr"><<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">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?</div><div class="m_1823733926161877260m_115211283745012700m_9094592728340752532m_-5726753707395278573HOEnZb"><div class="m_1823733926161877260m_115211283745012700m_9094592728340752532m_-5726753707395278573h5"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 30, 2016 at 9:58 AM, Nico Weber <span dir="ltr"><<a href="mailto:thakis@chromium.org" target="_blank">thakis@chromium.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">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.</p><div class="m_1823733926161877260m_115211283745012700m_9094592728340752532m_-5726753707395278573m_8455915324500932941HOEnZb"><div class="m_1823733926161877260m_115211283745012700m_9094592728340752532m_-5726753707395278573m_8455915324500932941h5">
<div class="gmail_extra"><br><div class="gmail_quote">On Sep 30, 2016 12:31 PM, "Reid Kleckner" <<a href="mailto:rnk@google.com" target="_blank">rnk@google.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">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:<div><a href="https://build.chromium.org/p/chromium.fyi/builders/ClangToTLinuxLLD/builds/1596/steps/compile/logs/stdio" target="_blank">https://build.chromium.org/p/c<wbr>hromium.fyi/builders/ClangToTL<wbr>inuxLLD/builds/1596/steps/comp<wbr>ile/logs/stdio</a></div><div><br>That build also doesn't involve LTO, so the long explanatory comment isn't helpful.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 28, 2016 at 2:10 PM, Rui Ueyama via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: ruiu<br>
Date: Wed Sep 28 16:10:54 2016<br>
New Revision: 282633<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=282633&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject?rev=282633&view=rev</a><br>
Log:<br>
Warn on empty archive files.<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D25044" rel="noreferrer" target="_blank">https://reviews.llvm.org/D2504<wbr>4</a><br>
<br>
Modified:<br>
lld/trunk/ELF/InputFiles.cpp<br>
lld/trunk/test/ELF/empty-archi<wbr>ve.s<br>
<br>
Modified: lld/trunk/ELF/InputFiles.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=282633&r1=282632&r2=282633&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/lld/trunk/ELF/InputFiles<wbr>.cpp?rev=282633&r1=282632&r2=2<wbr>82633&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/ELF/InputFiles.cpp (original)<br>
+++ lld/trunk/ELF/InputFiles.cpp Wed Sep 28 16:10:54 2016<br>
@@ -427,8 +427,17 @@ template <class ELFT> void ArchiveFile::<br>
File = check(Archive::create(MB), "failed to parse archive");<br>
<br>
// Read the symbol table to construct Lazy objects.<br>
- for (const Archive::Symbol &Sym : File->symbols())<br>
+ bool IsEmpty = true;<br>
+ for (const Archive::Symbol &Sym : File->symbols()) {<br>
Symtab<ELFT>::X->addLazyArchi<wbr>ve(this, Sym);<br>
+ IsEmpty = false;<br>
+ }<br>
+<br>
+ if (IsEmpty)<br>
+ warning(getName() + " has no symbol. Chances are you are doing "<br>
+ "an LTO build and forgot to use an ar command that can create "<br>
+ "a symbol table for LLVM bitcode files. If so, use llvm-ar or "<br>
+ "GNU ar + plugin.");<br>
}<br>
<br>
// Returns a buffer pointing to a member file containing a given symbol.<br>
<br>
Modified: lld/trunk/test/ELF/empty-archi<wbr>ve.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/empty-archive.s?rev=282633&r1=282632&r2=282633&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/lld/trunk/test/ELF/empty<wbr>-archive.s?rev=282633&r1=28263<wbr>2&r2=282633&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/test/ELF/empty-archi<wbr>ve.s (original)<br>
+++ lld/trunk/test/ELF/empty-archi<wbr>ve.s Wed Sep 28 16:10:54 2016<br>
@@ -1,3 +1,5 @@<br>
// RUN: llvm-ar rc %t.a<br>
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o<br>
-// RUN: ld.lld -shared %t.o %t.a -o t<br>
+// RUN: ld.lld -shared %t.o %t.a -o t 2>&1 | FileCheck %s<br>
+<br>
+// CHECK: has no symbol.<br>
<br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>
</blockquote></div></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div></div></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>