[llvm] [CodeGen] Sort .ctors in reverse on MinGW just like on other platforms (PR #68570)

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 10 01:18:26 PDT 2023


mstorsjo wrote:

> The condition also doesn't exactly match what `TargetLoweringObjectFileCOFF` checks for:
> 
> https://github.com/llvm/llvm-project/blob/f74e9f86a383868df66ae4f2e62589f9dfca1a0b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp#L1928
> 
> Are there any other targets that may need the fix? I guess Cygwin could but I don't know if LLVM even works for this target.

That's true, I guess it should be done for Cygwin as well; and matching the exact condition in `TargetLoweringObjectFileCOFF` would certainly be best.

Cygwin is not at all as well tested as MinGW, but there's been some recent effort on this front from @carlo-bramini, so I believe it might be working at least reasonably (but I'm fairly sure that there's lots of such corner case details that might need to be extended from `isWindowsGNUEnvironment()` into `isOSCygMing()`).

> Not quite sure if putting a target-specific special case in emitXXStructorList is really the best way to handle it. 

See the discussion from @efriedma-quic in https://github.com/llvm/llvm-project/pull/68571 for other ways to improve this. I guess that would boil down to
1. Extend the `UseInitArray` param to allow for a `Default` state
2. Hardcode the logic here for cases where we know `.ctors` is the only choice
3. Error out if the option is set in a conflicting way (e.g. `UseInitArray` set to explicit true on a MinGW target).

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


More information about the llvm-commits mailing list