This is an archive of the discontinued LLVM Phabricator instance.

[llvm-dlltool] Implement the --no-leading-underscore option
ClosedPublic

Authored by mstorsjo on Jun 7 2023, 4:41 AM.

Details

Summary

This requires being able to opt out from adding the leading underscores
in COFFModuleDefinition. Normally it is added automatically for I386
type targets. We could either move the decision entirely to all
callers, letting the caller check the machine type and decide whether
underscores should be added, or keep the logic mostly as is, but allowing
opting out from the behaviour on I386.

I went with keeping the interface as is for now, but I'm open for
discussion on the matter.

This goes on top of D152360, for people wanting to cherry pick it.

Diff Detail

Event Timeline

mstorsjo created this revision.Jun 7 2023, 4:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 7 2023, 4:41 AM
mstorsjo requested review of this revision.Jun 7 2023, 4:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 7 2023, 4:41 AM
mati865 added inline comments.Jun 7 2023, 7:32 AM
llvm/lib/Object/COFFModuleDefinition.cpp
143

I know nothing about ARM on Windows so double-check it but shouldn't this also check for ARM?

FYI, binutils' dlltool also has a variant of that flag going the other way (--leading-underscores), causing underscores to be added on arches other than i386 (the default for leading underscores is "only on i386" but the flag can either set it to true or false explicitly). I don't see the utility of that, but then again I didn't really see the utility of --no-leading-underscores either until rust was trying to use it.

mstorsjo added inline comments.Jun 7 2023, 9:16 AM
llvm/lib/Object/COFFModuleDefinition.cpp
143

Nope, out of the current 4 active architectures, only i386 uses such prefixes. And I don’t think the other ones (alpha, mips, sh4, ppc, ia64) used any prefix either, but I don’t know for sure about them.

In most cases, i386 is the weirdo - https://devblogs.microsoft.com/oldnewthing/20040914-00/?p=37873

FYI, binutils' dlltool also has a variant of that flag going the other way (--leading-underscores), causing underscores to be added on arches other than i386 (the default for leading underscores is "only on i386" but the flag can either set it to true or false explicitly). I don't see the utility of that, but then again I didn't really see the utility of --no-leading-underscores either until rust was trying to use it.

Indeed; I didn’t see much need for adding that either. After thinking about it, I do see the need for this flag though, making things more straightforward, bypassing all the extra adding/removing of decorations.

llvm/lib/Object/COFFModuleDefinition.cpp
143

Oh, and this matches the existing machine checks that get folded in here, which check specifically for i386.

jeremyd2019 accepted this revision.Jun 8 2023, 9:48 PM

I applied D152359 D152360 D152361 and this to llvm 16.0.4, and then used that to successfully bootstrap rust on MSYS2's CLANG32 environment, which previously failed due to the unknown --temp-prefix argument, and even when that argument was dropped by a wrapper around llvm-dlltool, failed with linker errors due to --no-leading-underscore not being implemented.

This revision is now accepted and ready to land.Jun 8 2023, 9:48 PM
This revision was landed with ongoing or failed builds.Jun 9 2023, 11:30 AM
This revision was automatically updated to reflect the committed changes.