[lld] [WIP][lld] Add lld warning for checking discarded sections via COMDAT (PR #74151)

Peter Smith via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 4 01:04:02 PST 2023


smithp35 wrote:

Not commenting directly on the code, just some experience from Arm's proprietary toolchain which, in its earlier form had a compiler and linker developed together so we had a bit more control over the incoming groups.

>From the description your definition of ODR violation is very strict, I think the only way it could be guaranteed to be satisfied is if every group where both identical in source, and compiled by the same compiler using the same compliation flages.

To summarise:
* Group contents can vary for legitimate reasons without being an ODR violation.
* LTO can trip these up, particularly for some C++ virtual methods at least with the libLLVMLTO code generator interface.
* The interface of what makes up a group is not well defined in ELF, I don't think section names matter at all.

The compiler also made much heavier use of groups for debug information to avoid dangling references when sections are removed (good for avoiding dangling references, bad for small object size and link time as it results in a lot more duplicate debug information).

As we understood ELF, the contents of comdat groups must be substitutable, in that the linker may choose any of the groups without affecting the program behaviour. There can be many situations where the contents of groups are different in contents for legitimate reasons. For example different optimisation levels, exceptions support (on Arm we have .ARM.exidx sections in groups), different debug (when debug is present in comdat group). Admittedly this isn't likely to be a problem on a system with homogenous command line choice, but it can happen when mixing binary only static libraries from different object producers.

We've also found instances where LTO (via the libLLVMLTO code generator which has a somewhat limited interface) will remove unused functions from groups which can defeat an ODR checker looking for the same "interface" as defined by global symbols.

In ELF, as far as we can tell, the only significant parts of a group are the global symbols that it defines. As these must be marked as undefined when the group is discarded. It is not permitted to make references to local symbols from outside the group so these are just implementation detail. 

https://github.com/llvm/llvm-project/pull/74151


More information about the llvm-commits mailing list