<div dir="ltr">(certainly seems like documenting this somewhere would be good, yes - perhaps a FAQ section or similar in: <a href="https://clang.llvm.org/docs/ThinLTO.html#usage">https://clang.llvm.org/docs/ThinLTO.html#usage</a> ? (that's the first result for thinlto on google, so seems like a good place for more documentation))</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jul 23, 2020 at 1:10 PM Tobias Hieta <<a href="mailto:tobias@plexapp.com">tobias@plexapp.com</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"><div dir="auto">Steven,<div dir="auto"><br></div><div dir="auto">Thanks so much for your help! How do you check the symtab in an archive so that I can learn and diagnose this by myself in the future?</div><div dir="auto"><br></div><div dir="auto">I had problems with libtool and llvm-ranlib before - but I will revisit and now I know the fallback is to set RANLIB=true</div><div dir="auto"><br></div><div dir="auto">I wonder if edge cases like this could have a good place to be documented since it's not obvious at all and hard to diagnose.</div><div dir="auto"><br></div><div dir="auto">Once again I am very grateful you took the time and looked at this! Have a great weekend!</div><div dir="auto"><br></div><div dir="auto">Tobias. </div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jul 23, 2020, 19:16 Steven Wu <<a href="mailto:stevenwu@apple.com" target="_blank">stevenwu@apple.com</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"><div style="overflow-wrap: break-word;">Hi Tobias<div><br></div><div>The problem is that your static archive has a SYMDEF that is empty, so linker thinks the static library provided doesn't contain any symbol. The reason for that is you are using the `ranlib` from Xcode, which is too old to understand the new bitcode object files produced by llvm 10.</div><div><br></div><div>There are lots of ways to fix that:</div><div>* The standard way to create static library on macOS is to use `libtool`. You can use DYLD_LIBRARY_PATH to point libtool to the libLTO from llvm 10. `ranlib` from Xcode is actually a symlink to `libtool` which provide a compatible legacy command line interface.</div><div>* Use llvm-ranlib from llvm 10 instead.</div><div>* Don't use `ranlib`. Then the static library won't have SYMDEF and linker will fallback to parse all the object file in the static library. That will sacrifice some link time but it will link correctly.</div><div><br></div><div>Steven</div><div><div><br><blockquote type="cite"><div>On Jul 22, 2020, at 11:41 PM, Tobias Hieta <<a href="mailto:tobias@plexapp.com" rel="noreferrer" target="_blank">tobias@plexapp.com</a>> wrote:</div><br><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Steven,<div><br></div><div>This is confusing. In the orig_command_line you can see that src/.libs/libogg.a is passed to the command line and even when running verbose clang I can see that clang invokes the linker with libogg.a on the line:</div><div><br></div><div> "/Applications/Xcode-11.3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -object_path_lto /var/folders/5c/85r7gp0909j5jbytzds1j7b40000gn/T/thinlto-74963a -lto_library /Applications/Xcode-11.3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -no_deduplicate -dynamic -arch x86_64 -macosx_version_min 10.15.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -o test /var/folders/5c/85r7gp0909j5jbytzds1j7b40000gn/T/test-d5e7a1.o src/.libs/libogg.a -debug_snapshot -lc++ -lSystem /Applications/Xcode-11.3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0/lib/darwin/libclang_rt.osx.a<br></div><div><br></div><div>When is the link_command file written and do you have any idea why this file is discarded at this point?</div><div><br></div><div>Using clang from xcode seems to work - it includes the file in archive_files.</div><div><br></div><div>I built libogg.a with both xcode/clang and <a href="http://llvm.org/" rel="noreferrer" target="_blank">llvm.org</a> clang and then tried to link to them and it reproduces each time that it won't link to the <a href="http://llvm.org/" rel="noreferrer" target="_blank">llvm.org</a> version while the xcode built one works fine. I have tarred the libogg files together and uploaded here:</div><div><br></div><div><a href="https://drive.google.com/file/d/1_mgN1w4iPCB8vz0KBDOc-5ypaNBaiFJA/view?usp=sharing" rel="noreferrer" target="_blank">https://drive.google.com/file/d/1_mgN1w4iPCB8vz0KBDOc-5ypaNBaiFJA/view?usp=sharing</a><br></div><div><br></div><div>I tried to link to it with:</div><div><br></div><div>clang++ -o test -flto=thin test.cpp libogg_xcode.a -I include<br></div><div><br></div><div>I am trying to think if I am doing something really bad here - but I have double checked everything I can think of and I am just downloading the <a href="http://llvm.org/" rel="noreferrer" target="_blank">llvm.org</a> package and don't have any customizations and then just pass the -flto=thin flag and use llvm-ar as ar.</div><div><br></div><div>Thanks again,</div><div>Tobias</div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jul 22, 2020 at 10:10 PM Steven Wu <<a href="mailto:stevenwu@apple.com" rel="noreferrer" target="_blank">stevenwu@apple.com</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"><div>Looks like your static library is not even pulled into the link command so the static library is not even in the snapshot. From the link command in the snapshot, the static library is not on the command line from snapshot:<div><br><div>/Applications/Xcode-11.3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld -Z -demangle -object_path_lto /var/folders/5c/85r7gp0909j5jbytzds1j7b40000gn/T/thinlto-bf51d2 -lto_library data_files/libLTO.dylib -no_deduplicate -dynamic -arch x86_64 -macosx_version_min 10.15.0 -debug_snapshot -filelist objects/filelist dylibs/libSystem.tbd dylibs/libc++.tbd<br><br><div><br></div><div>Steven</div><div><br></div><div><br><blockquote type="cite"><div>On Jul 22, 2020, at 11:42 AM, Tobias Hieta <<a href="mailto:tobias@plexapp.com" rel="noreferrer" target="_blank">tobias@plexapp.com</a>> wrote:</div><br><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hello,<div><br></div><div>Thanks for the reply Teresa and Steven,</div><div><br></div><div>I uploaded the snapshot to GDrive: <a href="https://drive.google.com/file/d/11Ngst9FOnVL4fWYlKalzoFXL--B1SaOb/view?usp=sharing" rel="noreferrer" target="_blank">https://drive.google.com/file/d/11Ngst9FOnVL4fWYlKalzoFXL--B1SaOb/view?usp=sharing</a></div><div><br></div><div>My ld version is:</div><div><br></div><div><div>➜ ld -v</div><div>@(#)PROGRAM:ld  PROJECT:ld64-530</div><div>BUILD 18:57:17 Dec 13 2019</div><div>configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em</div><div>LTO support using: LLVM version 11.0.0, (clang-1100.0.33.17) (static support for 23, runtime is 23)</div><div>TAPI support using: Apple TAPI version 11.0.0 (tapi-1100.0.11)</div></div><div><br></div><div>Since that said it was using LTO from Xcode I thought that might be the problem - but when I run clang with -v to see the linker invocation it seems to pass the correct libLTO.dylib:</div><div> </div><div>"/usr/bin/ld" -demangle -object_path_lto /var/folders/5c/85r7gp0909j5jbytzds1j7b40000gn/T/thinlto-a8ae97 -lto_library /Users/tobias/tmp/clang+llvm-10.0.1-x86_64-apple-darwin/lib/libLTO.dylib -no_deduplicate -dynamic -arch x86_64 -platform_version macos 10.15.0 10.15 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -o test /var/folders/5c/85r7gp0909j5jbytzds1j7b40000gn/T/test-d0eb14.o src/.libs/libogg.a -debug_snapshot -lc++ -lSystem /Users/tobias/tmp/clang+llvm-10.0.1-x86_64-apple-darwin/lib/clang/10.0.1/lib/darwin/libclang_rt.osx.a<br></div><div><br></div><div>Thanks again,</div><div>Tobias</div></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jul 22, 2020 at 7:20 PM Steven Wu <<a href="mailto:stevenwu@apple.com" rel="noreferrer" target="_blank">stevenwu@apple.com</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"><div>This is usually a problem that is not using llvm-ar. I cannot reproduce this problem with either llvm 10.0 or TOT version. Which linker version are you using? You can also try pass "-Wl,-debug_snapshot" to the command where the error produces and then locate the "*.ld-snapshot" in /tmp directory and attach that as a reproducer.<div><br></div><div>Steven<br><div><br><blockquote type="cite"><div>On Jul 22, 2020, at 8:41 AM, Teresa Johnson <<a href="mailto:tejohnson@google.com" rel="noreferrer" target="_blank">tejohnson@google.com</a>> wrote:</div><br><div><div dir="ltr" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none">Adding Steven Wu who can hopefully help as this is MacOS. Unfortunately, I don't have a way to run the MacOS compiler myself, and it uses the old LTO API which I am less familiar with. Typically these issues happen if you don't use llvm-ar, but it looks like you are using that so I'm not sure.<div><br></div><div>Teresa</div></div><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div class="gmail_quote" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div dir="ltr" class="gmail_attr">On Wed, Jul 22, 2020 at 12:29 AM Tobias Hieta <<a href="mailto:tobias@plexapp.com" rel="noreferrer" target="_blank">tobias@plexapp.com</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">David,<br><br>Thanks for looking into this. I did a small reproduction on my machine<br>outside of my build system. So here is how to reproduce:<br><br>Download<span> </span><a href="https://downloads.xiph.org/releases/ogg/libogg-1.3.4.tar.xz" rel="noreferrer noreferrer" target="_blank">https://downloads.xiph.org/releases/ogg/libogg-1.3.4.tar.xz</a><br>Download llvm-10.0.1 macOS binary<br><br>export PATH=<path to llvm/bin>:$PATH<br>export SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk<br><br>untar libogg<br>AR=llvm-ar CC=clang CXX=clang++ CFLAGS="-flto=thin<br>-mmacosx-version-min=10.9" LDFLAGS=-flto=thin ./configure<br>--disable-shared --enable-static<br>make -j20<br><br>Then try to link to the library in a small C++ program - I used this:<br><br>#include <iostream><br>#include "ogg/ogg.h"<br><br>using namespace std;<br><br>int main()<br>{<br>ogg_stream_state os;<br>if (ogg_stream_init(&os, 123) == 0)<br>cout << "Initialized stream succesfully" << endl;<br><br>return 0;<br>}<br><br>And from the libogg directory I linked to it like this:<br><br>clang++ -o test -flto=thin test.cpp src/.libs/libogg.a -I include<br><br>undef: _ogg_stream_init<br>Undefined symbols for architecture x86_64:<br>"_ogg_stream_init", referenced from:<br>_main in 0.x86_64.thinlto.o<br>ld: symbol(s) not found for architecture x86_64<br>clang-10: error: linker command failed with exit code 1 (use -v to see<br>invocation)<br><br>hope this helps - thanks!<br><br>On Wed, Jul 22, 2020 at 9:11 AM David Blaikie <<a href="mailto:dblaikie@gmail.com" rel="noreferrer" target="_blank">dblaikie@gmail.com</a>> wrote:<br>><br>> Got a link to the source/build instructions?<br>><br>> This sort of thing happens more often in C++ with templates where one<br>> object depends (incorrectly) on an implicit instantiation created in<br>> another object, rather than carrying its own instantiation.<br>><br>> Not sure what might cause it in C code.<br>><br>> On Tue, Jul 21, 2020 at 11:47 PM Tobias Hieta via llvm-dev<br>> <<a href="mailto:llvm-dev@lists.llvm.org" rel="noreferrer" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>> ><br>> > Hello,<br>> ><br>> > I am building libogg with clang (10.0.1) on macOS and if I pass<br>> > "-flto=thin" to C and LDFLAGS it will not link correctly claiming<br>> > missing symbols when linking to the archive (libogg.a).<br>> ><br>> > undef: _ogg_stream_init<br>> > Undefined symbols for architecture x86_64:<br>> > "_ogg_stream_init", referenced from:<br>> > _main in lto.o<br>> ><br>> > Removing lto=thin fixes the problem. Inspecting the AR libs with<br>> > llvm-nm I see the symbol there (but without address):<br>> ><br>> > not working archive:<br>> > ---------------- T _ogg_stream_init<br>> ><br>> > working archive:<br>> > 0000000000000200 T _ogg_stream_init<br>> ><br>> > My guess is that this output is correct since the archive contains<br>> > bitcode in the thin lto case and otherwise it's the finished object.<br>> ><br>> > It seems to me that the LTO decides to not include this symbol? It's<br>> > defined like this:<br>> ><br>> > extern int ogg_stream_init(ogg_stream_state *os,int serialno);<br>> ><br>> > llvm-ar is used to create the archive.<br>> ><br>> > Is there any good way to debug this?<br>> ><br>> > Thanks,<br>> > Tobias<br>> > _______________________________________________<br>> > LLVM Developers mailing list<br>> ><span> </span><a href="mailto:llvm-dev@lists.llvm.org" rel="noreferrer" target="_blank">llvm-dev@lists.llvm.org</a><br>> ><span> </span><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br></blockquote></div><br clear="all" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><br></div><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;float:none;display:inline">--<span> </span></span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div dir="ltr" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div dir="ltr"><div><span style="font-family:Times;font-size:inherit"><table cellspacing="0" cellpadding="0"><tbody><tr style="color:rgb(85,85,85);font-family:sans-serif;font-size:small"><td nowrap style="border-top:2px solid rgb(213,15,37)">Teresa Johnson |</td><td nowrap style="border-top:2px solid rgb(51,105,232)"> Software Engineer |</td><td nowrap style="border-top:2px solid rgb(0,153,57)"> <a href="mailto:tejohnson@google.com" rel="noreferrer" target="_blank">tejohnson@google.com</a> |</td></tr></tbody></table></span></div></div></div></div></blockquote></div><br></div></div></blockquote></div>
</div></blockquote></div><br></div></div></div></blockquote></div>
</div></blockquote></div><br></div></div></blockquote></div>
</blockquote></div>