Re: Symbol resolution differs when building with LTO compared to building without

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Alice,

on 2020/7/10 上午4:00, Alice Wang wrote:
> Hi Kewen,
> 
> The ticket you linked does sound similar. And thanks for your suggestions. I tried them out and summarized the results below:
> 
> 1) Don't use linker-plugin, use -fno-use-linker-plugin explicitly.
> 
> The build finishes and outputs the result I expect. My custom implementation of _write is pulled into the final binary. But wouldn't -fno-use-linker-plugin effectively disable LTO in the sense that my project won't be able to take advantage of more aggressive interprocedural optimizations? 
> 

Yes, I just noticed your write.c has its own static library (archive), you would need plugin
to extract these files in archive.  Do you mind to try with option "-u _write" in the linking
command to explicitly claim symbol _write is required.  Hope it can pull your expected object
file from the archive.

> 2) Use shared library instead of static library for _write library.
> 
> I can't use a shared library in my case since I'm compiling for an embedded target without any sort of dynamic linker. 
> 

OK.

> 3) -Wl,--whole-archive -l<your_static_write_library> -Wl,--no-whole-archive
> 
> I changed the build command to the following:
>  @$(CC) $(FLAGS)  -fuse-linker-plugin -fno-common -Wl,-Map=output.map -Wl,--gc-sections -o $@ -Wl,--start-group main.a -lc -Wl,--end-group -Wl,--whole-archive _my_write.a -Wl,--no-whole-archive
> 

As you mentioned your project is for embedded env, then I guess the size is critical and
this option isn't acceptable for you since it could pull in some useless objects from
the archive.  So it looks you can just ignore it.  :)


BR,
Kewen



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux