[cfe-dev] Compiling with both -flto and -g -- is it supposed to work ?
Philippe Blain via cfe-dev
cfe-dev at lists.llvm.org
Thu Jun 11 19:56:22 PDT 2020
Hi David,
> Le 9 juin 2020 à 11:16, David Blaikie <dblaikie at gmail.com> a écrit :
>
> Not sure how this works on MacOS where object files are needed for
> debugging - on Linux lto works with -g because debug info is linked
> into the final binary. (CC'd some Apple folks who might know how this
> is supposed to work)
Thanks.
I ended up making additional tests, and adding `-v` to the clang invocation
on a simple hello-world type project made me realize
that I need to add `-Wl,object_path_lto,lto.o` to the linking command
if doing compilation and liking in separate steps (as is usually
the case with Make- and Automake- based build system!)
This flag is automatically added by the driver if doing compilation+linking in a single step,
and if it is not passed to the linker, `man ld` reveals that the temporary object file used
for link time optimization is deleted after the linking step is finished, so the executable contains
a reference to `/tmp/lto.o` which does not exist anymore when debugging actually starts
(I guess this path is hardcoded in ld64's code, I haven't checked that.)
Adding the flag as above keeps `lto.o` in the build directory, and debuggers are able to read
the debugging symbols. Also, `dsymutil`can then be run manually to create the dSYM bundle (which
is also done automatically if compiling and linking in a single step).
I'm not sure anything can be done to improve the situation... maybe add some notes in the
LTO documentation ? I could try to do that.
Cheers,
Philippe.
More information about the cfe-dev
mailing list