<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jan 13, 2021 at 6:26 PM Fangrui Song via Phabricator <<a href="mailto:reviews@reviews.llvm.org">reviews@reviews.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">MaskRay added a comment.<br>
<br>
In D80391#2497018 <<a href="https://reviews.llvm.org/D80391#2497018" rel="noreferrer" target="_blank">https://reviews.llvm.org/D80391#2497018</a>>, @inglorion wrote:<br>
<br>
> For Chrome on Chrome OS, this is <a href="https://crbug.com/1158215" rel="noreferrer" target="_blank">https://crbug.com/1158215</a><br>
><br>
> Here, we saw our links fail with "output file too large". Investigation revealed that debug info was being included in the binary, instead of in .dwo files as expected. That turned out to be caused by this change.<br>
><br>
> It seems that there are cases where -gsplit-dwarf is passed, but it does not take effect because there isn't also a -g (or -g<level>) option:<br>
><br>
> clang -c -fthinlto-index=foo.o.thinlto.bc -gsplit-dwarf foo.o -o foo.bin.o<br>
><br>
> Shows no .dwo file and debug info in foo.bin.o, whereas<br>
><br>
> clang -c -fthinlto-index=foo.o.thinlto.bc -gsplit-dwarf -g foo.o -o foo.bin.o<br>
><br>
> shows a .dwo file which is referenced from foo.bin.o<br>
><br>
> The only thing that is different here is that the latter command has "-g" whereas the former doesn't.<br>
><br>
> In other words, the new implementation still doesn't make -g and -gsplit-dwarf fully orthogonal; instead of -gsplit-dwarf always turning on debug fission, it *only* turns it on when there is also a -g or -g<level> option - at least in distributed ThinLTO code generation.<br>
><br>
> It seems that orthogonality was the motivation for this change, and that -gsplit-dwarf without -g is supposed to work in the linker (per MaskRay's comment about -g being ignored by the linker).<br>
><br>
> Can we make it so that -gsplit-dwarf turns on debug fission and we then use that even if no -g options were passed?<br>
<br>
I am still confused what the problem is. I added some comments to the following distributed ThinLTO example.<br>
Both -gsplit-dwarf and -g are needed for the ThinLTO backend compile step (`-fthinlto-index=`)</blockquote><div><br></div><div>^ this I would consider to be a bug. -g should be needed to generate debug info into the IR, and -gsplit-dwarf should be needed to choose how debug info already in the IR should be placed into object files or dwo files.<br><br>Usually (non-LTO) these two steps are in the same compile, so -g and -gsplit-dwarf go together. But for LTO cases, I think it's suitable for -g to be needed for IR generation, and -gsplit-dwarf to be needed for object code generation, without needing -g as well in that latter step (the -g was already specified at IR generation time, and that shoul be enough).<br><br>We can see that behavior I'm describing as desirable in implicit ThinLTO I showed earlier in the thread.<br><br>I suggest this should be the desired behavior, because -g generally has no effect on IR->object code generation, so it seems strange/unnecessary to me to gate -gsplit-dwarf behind -g in that case. The -g was already specified and used during IR generation (& the -gN level, -gmlt behavior-etc has all been handled in IR generation (or embedded in the IR for use later) - so to me, specifying -g again during object code generation would be/is strange, because any special values would be ignored (-g1/g2/g3/etc would not be respected - the N value would only be respected when passed to the IR generation step))</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">:<br>
<br>
cat > ./a.c <<eof<br>
int foo();<br>
int main() { return foo();}<br>
eof<br>
echo 'int foo() {return 42; }' > ./b.c<br>
cat > ./Makefile <<eof<br>
clang := /tmp/RelA/bin/clang<br>
all: final_link<br>
<br>
compile a.o b.o a.indexing.o b.indexing.o: a.c b.c<br>
# -gsplit-dwarf in the initial compile is a no-op.<br>
$(clang) -gsplit-dwarf -g -O2 -c -flto=thin -fthin-link-bitcode=a.indexing.o a.c<br>
$(clang) -gsplit-dwarf -g -O2 -c -flto=thin -fthin-link-bitcode=b.indexing.o b.c<br>
<br>
thin_link lto/a.o.thinlto.bc lto/b.o.thinlto.bc a.rsp: a.indexing.o b.indexing.o<br>
$(clang) -fuse-ld=lld -Wl,--thinlto-index-only=a.rsp -Wl,--thinlto-prefix-replace=';lto/' -Wl,--thinlto-object-suffix-replace='.indexing.o;.o' a.indexing.o b.indexing.o<br>
<br>
thinlto_backend lto/a.o lto/b.o: a.o b.o lto/a.o.thinlto.bc lto/b.o.thinlto.bc<br>
# This does not produce lto/a.dwo<br>
# Both -gsplit-dwarf and -g are needed to get lto/a.dwo<br>
$(clang) -g -O2 -c -fthinlto-index=lto/a.o.thinlto.bc a.o -o lto/a.o<br>
$(clang) -g -O2 -c -fthinlto-index=lto/b.o.thinlto.bc b.o -o lto/b.o<br>
<br>
final_link exe: lto/a.o lto/b.o a.rsp<br>
$(clang) -fuse-ld=lld @a.rsp -o exe<br>
<br>
clean:<br>
$(RM) -f *.o lto/*.o lto/*.bc lto/*.dwo<br>
eof<br>
mkdir -p ./lto<br>
<br>
<br>
Repository:<br>
rG LLVM Github Monorepo<br>
<br>
CHANGES SINCE LAST ACTION<br>
<a href="https://reviews.llvm.org/D80391/new/" rel="noreferrer" target="_blank">https://reviews.llvm.org/D80391/new/</a><br>
<br>
<a href="https://reviews.llvm.org/D80391" rel="noreferrer" target="_blank">https://reviews.llvm.org/D80391</a><br>
<br>
</blockquote></div></div>