Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an alias object to the import lib #2734

Merged
merged 16 commits into from
May 24, 2022

Conversation

barcharcraz
Copy link
Member

We used to use an internal "aliasobj" tool to generate this object, but it would be a ton of work to release it. Thus, we switched to using /ALTERNATENAME, however we put that in the directives section of xonce2.cpp with a static init function call pointing there from shared mutex. This was a problem because if you compile with an old toolset but later link with a new toolset the linker has no way of knowing it should be pulling in the new xonce2.cpp.

This keeps the /ALTERNATENAME directives (though they could later be removed, I suppose) but additionally adds an alias object (alias.asm.obj) to the import library that contains "real" weak external symbols.

This generates an object file that's very similar to what aliasobj would have done, except there's only one object, instead of one per symbol (I think this is fine), and the object is more "complete" (it contains debug info, and a .text section (that's empty) and so on).

The cmake has been updated quite extensively to specify options for the correct language. I only bothered to do this for the options that actually make it to the implib objects compilation.

A simple test has been added, this test uses it own prefix with just the /Mxx options.

Fixes #2655

This is enabled on x86 and x64 only, as it relies on a MASM assembly file,
still, it's not actually assembly, there's no _code_ generated, just objects
with the correct sections.

whoops

fix
@barcharcraz barcharcraz requested a review from a team as a code owner May 20, 2022 03:51
CMakeLists.txt Outdated Show resolved Hide resolved
stl/CMakeLists.txt Show resolved Hide resolved
stl/src/alias.asm Outdated Show resolved Hide resolved
stl/src/alias.asm Outdated Show resolved Hide resolved
Copy link
Member

@CaseyCarter CaseyCarter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is "approve with suggestions": I wouldn't be upset if we merge and cleanup my nitpicks later since this is high priority.

stl/src/alias.asm Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
@CaseyCarter CaseyCarter added bug Something isn't working high priority Important! labels May 20, 2022
stl/CMakeLists.txt Show resolved Hide resolved
stl/src/alias.asm Outdated Show resolved Hide resolved
stl/src/alias.asm Outdated Show resolved Hide resolved
CMakeLists.txt Show resolved Hide resolved
@StephanTLavavej
Copy link
Member

@CaseyCarter I pushed minor changes after you approved.

@barcharcraz Thank you for fixing this! 😻 I had no idea the assembler could be used to achieve this.

@StephanTLavavej
Copy link
Member

I have filed https://gitlab.kitware.com/cmake/cmake/-/issues/23537 'MSVC assembler shows "Assembling" messages that should be suppressed'.

@StephanTLavavej StephanTLavavej self-assigned this May 21, 2022
@StephanTLavavej
Copy link
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej
Copy link
Member

✅ 🎉 😸

I have verified the end-to-end scenario for both x86 and x64. I built a program using std::call_once() with the 16.11 toolset. Attempting to perform the final link with 17.3 Preview 1 failed with the unresolved externals, and it succeeded with this PR. (I made sure to consume the 16.11-built object file, and it printed that it was built with _MSC_VER == 1929, so I definitely wasn't compiling it fresh.)

@StephanTLavavej
Copy link
Member

I've pushed changes to add this to MSBuild.

@StephanTLavavej
Copy link
Member

  • Trivial adjacent-add conflict in CMakeLists.txt, placed the WinSDK check before the architecture check.
  • Trivial adjacent-add conflict in tests/std/test.lst.

@StephanTLavavej StephanTLavavej merged commit fc9232d into microsoft:main May 24, 2022
@StephanTLavavej
Copy link
Member

Thanks for fixing this major bug that I wrote! 🐞 😻 🛠️

fsb4000 pushed a commit to fsb4000/STL that referenced this pull request Aug 13, 2022
Co-authored-by: Stephan T. Lavavej <stl@microsoft.com>
@@ -176,6 +176,18 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
</BuildFiles>
</ItemGroup>

<ItemGroup Condition="'$(BuildArchitecture)' == 'i386' or '$(BuildArchitecture)' == 'amd64'">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this only fixes this for x86 and x64 but not for arm64?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The aliases are not needed on ARM64 IIRC, this is for backwards compatibility on x86/x64 with code that predates ARM64 support. Are you having an issue building some ARM64 code?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I have the same LNK2019: unresolved external symbol errors on ARM64 and have applied the AlternateName workaround for arm64 for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend opening a new issue with repro steps then. Are you targetting ARM64EC with some old x64 binary?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a normal ARM64 static library similarly compiled before this change went in, causing the exact same symptoms after this change when included in a dll targeting ARM64.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working high priority Important!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replacing checked-in OBJ files with /ALTERNATENAME broke linker compatibility
5 participants