-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[LLD][COFF] Add support for including native ARM64 objects in ARM64EC images #137653
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -190,7 +190,6 @@ static bool compatibleMachineType(COFFLinkerContext &ctx, MachineTypes mt) { | |
case ARM64: | ||
return mt == ARM64 || mt == ARM64X; | ||
case ARM64EC: | ||
return isArm64EC(mt) || mt == AMD64; | ||
case ARM64X: | ||
return isAnyArm64(mt) || mt == AMD64; | ||
case IMAGE_FILE_MACHINE_UNKNOWN: | ||
|
@@ -499,7 +498,7 @@ void LinkerDriver::parseDirectives(InputFile *file) { | |
case OPT_entry: | ||
if (!arg->getValue()[0]) | ||
Fatal(ctx) << "missing entry point symbol name"; | ||
ctx.forEachSymtab([&](SymbolTable &symtab) { | ||
ctx.forEachActiveSymtab([&](SymbolTable &symtab) { | ||
symtab.entry = symtab.addGCRoot(symtab.mangle(arg->getValue()), true); | ||
}); | ||
break; | ||
|
@@ -657,9 +656,13 @@ void LinkerDriver::setMachine(MachineTypes machine) { | |
|
||
ctx.config.machine = machine; | ||
|
||
if (machine != ARM64X) { | ||
if (!isArm64EC(machine)) { | ||
ctx.symtab.machine = machine; | ||
} else { | ||
// Set up a hybrid symbol table on ARM64EC/ARM64X. This is primarily useful | ||
// on ARM64X, where both the native and EC symbol tables are meaningful. | ||
// However, since ARM64EC can include native object files, we also need to | ||
// support a hybrid symbol table there. | ||
ctx.symtab.machine = ARM64EC; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would probably be good to add a comment here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a comment, thanks for review! |
||
ctx.hybridSymtab.emplace(ctx, ARM64); | ||
} | ||
|
@@ -979,7 +982,7 @@ void LinkerDriver::createImportLibrary(bool asLib) { | |
}; | ||
|
||
getExports(ctx.symtab, exports); | ||
if (ctx.hybridSymtab) | ||
if (ctx.config.machine == ARM64X) | ||
getExports(*ctx.hybridSymtab, nativeExports); | ||
|
||
std::string libName = getImportName(asLib); | ||
|
@@ -1383,13 +1386,13 @@ void LinkerDriver::maybeExportMinGWSymbols(const opt::InputArgList &args) { | |
return; | ||
|
||
if (ctx.symtab.hadExplicitExports || | ||
(ctx.hybridSymtab && ctx.hybridSymtab->hadExplicitExports)) | ||
(ctx.config.machine == ARM64X && ctx.hybridSymtab->hadExplicitExports)) | ||
return; | ||
if (args.hasArg(OPT_exclude_all_symbols)) | ||
return; | ||
} | ||
|
||
ctx.forEachSymtab([&](SymbolTable &symtab) { | ||
ctx.forEachActiveSymtab([&](SymbolTable &symtab) { | ||
AutoExporter exporter(symtab, excludedSymbols); | ||
|
||
for (auto *arg : args.filtered(OPT_wholearchive_file)) | ||
|
@@ -2305,7 +2308,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) { | |
if (auto *arg = args.getLastArg(OPT_deffile)) { | ||
// parseModuleDefs mutates Config object. | ||
ctx.symtab.parseModuleDefs(arg->getValue()); | ||
if (ctx.hybridSymtab) { | ||
if (ctx.config.machine == ARM64X) { | ||
// MSVC ignores the /defArm64Native argument on non-ARM64X targets. | ||
// It is also ignored if the /def option is not specified. | ||
if (auto *arg = args.getLastArg(OPT_defarm64native)) | ||
|
@@ -2332,7 +2335,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) { | |
} | ||
|
||
// Handle /entry and /dll | ||
ctx.forEachSymtab([&](SymbolTable &symtab) { | ||
ctx.forEachActiveSymtab([&](SymbolTable &symtab) { | ||
llvm::TimeTraceScope timeScope("Entry point"); | ||
if (auto *arg = args.getLastArg(OPT_entry)) { | ||
if (!arg->getValue()[0]) | ||
|
@@ -2364,7 +2367,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) { | |
llvm::TimeTraceScope timeScope("Delay load"); | ||
for (auto *arg : args.filtered(OPT_delayload)) { | ||
config->delayLoads.insert(StringRef(arg->getValue()).lower()); | ||
ctx.forEachSymtab([&](SymbolTable &symtab) { | ||
ctx.forEachActiveSymtab([&](SymbolTable &symtab) { | ||
if (symtab.machine == I386) { | ||
symtab.delayLoadHelper = symtab.addGCRoot("___delayLoadHelper2@8"); | ||
} else { | ||
|
@@ -2538,7 +2541,9 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) { | |
u->setWeakAlias(symtab.addUndefined(to)); | ||
} | ||
} | ||
}); | ||
|
||
ctx.forEachActiveSymtab([&](SymbolTable &symtab) { | ||
// If any inputs are bitcode files, the LTO code generator may create | ||
// references to library functions that are not explicit in the bitcode | ||
// file's symbol table. If any of those library functions are defined in | ||
|
@@ -2568,7 +2573,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) { | |
|
||
// Handle /includeglob | ||
for (StringRef pat : args::getStrings(args, OPT_incl_glob)) | ||
ctx.forEachSymtab( | ||
ctx.forEachActiveSymtab( | ||
[&](SymbolTable &symtab) { symtab.addUndefinedGlob(pat); }); | ||
|
||
// Create wrapped symbols for -wrap option. | ||
|
@@ -2685,12 +2690,12 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) { | |
// need to create a .lib file. In MinGW mode, we only do that when the | ||
// -implib option is given explicitly, for compatibility with GNU ld. | ||
if (config->dll || !ctx.symtab.exports.empty() || | ||
(ctx.hybridSymtab && !ctx.hybridSymtab->exports.empty())) { | ||
(ctx.config.machine == ARM64X && !ctx.hybridSymtab->exports.empty())) { | ||
llvm::TimeTraceScope timeScope("Create .lib exports"); | ||
ctx.forEachSymtab([](SymbolTable &symtab) { symtab.fixupExports(); }); | ||
ctx.forEachActiveSymtab([](SymbolTable &symtab) { symtab.fixupExports(); }); | ||
if (!config->noimplib && (!config->mingw || !config->implib.empty())) | ||
createImportLibrary(/*asLib=*/false); | ||
ctx.forEachSymtab( | ||
ctx.forEachActiveSymtab( | ||
[](SymbolTable &symtab) { symtab.assignExportOrdinals(); }); | ||
} | ||
|
||
|
@@ -2756,7 +2761,8 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) { | |
|
||
if (ctx.symtab.isEC()) | ||
ctx.symtab.initializeECThunks(); | ||
ctx.forEachSymtab([](SymbolTable &symtab) { symtab.initializeLoadConfig(); }); | ||
ctx.forEachActiveSymtab( | ||
[](SymbolTable &symtab) { symtab.initializeLoadConfig(); }); | ||
|
||
// Identify unreferenced COMDAT sections. | ||
if (config->doGC) { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this change makes us create two symbol tables for all arm64ec linking, even if the very fast majority of them ever only will use one of them?
That feels odd, but I guess it's good for consistency - otherwise we'd probably have lots of bugs for the very rare cases when we do need both symbol tables for arm64ec. And I guess this is the change which forces the extra
(EC symbol)
to be printed in many tests.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that’s right, this is the core part of the change; the rest of the patch updates various components to handle it properly. The extra
(EC symbol)
annotation doesn’t add much value when there’s only a single symbol table, but it becomes quite useful with this PR. If someone accidentally passes a native object file, error messages that include(native symbol)
should make the issue easy to diagnose.