mstorsjo / llvm-mingw

An LLVM/Clang/LLD based mingw-w64 toolchain

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Does llvm-mingw support -faddrsig?

Andarwinux opened this issue · comments

Hi, the llvm documentation says that only ELF supports -faddrsig, but I'm seeing some COFF addrsig commits.
I'm building mpv with --icf=safe using x86_64-w64-mingw32-clang+lld, but I don't see any size reduction.
Does -faddrsig work on COFF? Is the documentation not updated or is clang/lld bug?
Thanks.

Hi, the llvm documentation says that only ELF supports -faddrsig, but I'm seeing some COFF addrsig commits. I'm building mpv with --icf=safe using x86_64-w64-mingw32-clang+lld, but I don't see any size reduction. Does -faddrsig work on COFF? Is the documentation not updated or is clang/lld bug?

-faddrsig in itself does have an effect for COFF targets (and is enabled by default), and it produces .addrsig directives in the assembly output.

Back when I hooked up the --icf= option in the LLD MinGW linker, there was no safe ICF implemented in the COFF target in LLD, see this comment here from 2017: https://reviews.llvm.org/D40019?id=122818#inline-349280

Apparently some level of "safe ICF" was implemented in the LLD COFF linker in 2021: llvm/llvm-project@5bdc5e7

To take that into use, the LLD MinGW interface here https://github.com/llvm/llvm-project/blob/llvmorg-17.0.3/lld/MinGW/Driver.cpp#L367-L377, would need to be updated to pass -opt:safeicf when the MinGW interface is called with --icf=safe. I wasn't aware of this case until today.

And I guess even then, we probably would need to recheck the cautions pointed out in 2017, "Safe ICF leveraged certain x86_32 ELF relocations that COFF lacks, and failing that, relies on knowledge about the Itanium C++ name mangling rules. LLD doesn't implement anything like that."

I made a PR to add support for this: llvm/llvm-project#70037

FYI, the latest nightly build at https://github.com/mstorsjo/llvm-mingw/releases/nightly should have full support for this feature, if you want to give it a try. (In case there are some issues with it, it's always nice to have it tested in advance before the 18.x release branch is made in a few months.)

Tested, works great, reduced almost the same size compared to --icf=all, no other problems found.
Also, on lld17, -Xlink=-opt:safeicf has the same effect.