Skip to content

Commit 4e9d5a3

Browse files
authored
[LLD][COFF] Add support for the -defArm64Native argument (#123850)
MSVC ignores the `/defArm64Native` argument on non-ARM64X targets. It is also ignored if the `/def` option is not specified.
1 parent a2c683b commit 4e9d5a3

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

lld/COFF/Driver.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,6 +1795,9 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
17951795
setMachine(machine);
17961796
}
17971797
}
1798+
1799+
// Most of main arguments apply either to both or only to EC symbol table on
1800+
// ARM64X target.
17981801
SymbolTable &mainSymtab = ctx.hybridSymtab ? *ctx.hybridSymtab : ctx.symtab;
17991802

18001803
// Handle /nodefaultlib:<filename>
@@ -2291,6 +2294,12 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
22912294
if (auto *arg = args.getLastArg(OPT_deffile)) {
22922295
// parseModuleDefs mutates Config object.
22932296
mainSymtab.parseModuleDefs(arg->getValue());
2297+
if (ctx.hybridSymtab) {
2298+
// MSVC ignores the /defArm64Native argument on non-ARM64X targets.
2299+
// It is also ignored if the /def option is not specified.
2300+
if (auto *arg = args.getLastArg(OPT_defarm64native))
2301+
ctx.symtab.parseModuleDefs(arg->getValue());
2302+
}
22942303
}
22952304

22962305
// Handle generation of import library from a def file.

lld/COFF/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ def incl : Joined<["/", "-", "/?", "-?"], "include:">,
140140
def deffile : Joined<["/", "-", "/?", "-?"], "def:">,
141141
HelpText<"Use module-definition file">;
142142

143+
def defarm64native
144+
: P<"defarm64native",
145+
"Use a module-definition file for the native view in a hybrid image.">;
143146
def debug : F<"debug">, HelpText<"Embed a symbol table in the image">;
144147
def debug_opt : P<"debug", "Embed a symbol table in the image with option">;
145148
def debugtype : P<"debugtype", "Debug Info Options">;

lld/test/COFF/arm64x-export.test

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,29 @@ EXPORTS-BOTH-NEXT: RVA: 0x3000
162162
EXPORTS-BOTH-NEXT: }
163163
EXPORTS-BOTH-NEXT: }
164164

165+
# Export using both the -def and -defarm64native arguments.
166+
167+
RUN: lld-link -machine:arm64x -dll -out:out-def-both.dll arm64ec-func.obj arm64-func.obj \
168+
RUN: loadconfig-arm64.obj loadconfig-arm64ec.obj -def:func.def -defarm64native:func.def -noentry
169+
RUN: llvm-objdump -d out-def-both.dll | FileCheck --check-prefix=DISASM-BOTH %s
170+
RUN: llvm-readobj --headers --coff-exports out-def-both.dll | FileCheck --check-prefix=EXPORTS-BOTH %s
171+
172+
# -defarm64native is ignored if -def is not specified.
173+
174+
RUN: lld-link -machine:arm64x -dll -out:out-def-native.dll arm64ec-func.obj arm64-func.obj \
175+
RUN: loadconfig-arm64.obj loadconfig-arm64ec.obj -defarm64native:func.def -noentry
176+
RUN: llvm-readobj --headers --coff-exports out-def-native.dll | FileCheck --check-prefix=NO-EXPORT %s
177+
NO-EXPORT: ExportTableRVA: 0x0
178+
NO-EXPORT: ExportTableSize: 0x0
179+
NO-EXPORT: HybridObject {
180+
NO-EXPORT: ExportTableRVA: 0x0
181+
NO-EXPORT: ExportTableSize: 0x0
182+
NO-EXPORT: }
183+
184+
# -defarm64native is ignored on ARM64 target.
185+
186+
RUN: lld-link -machine:arm64 -dll -out:out-arm64-def.dll arm64-func.obj -defarm64native:invalid.def -def:func.def -noentry 2>&1 | count 0
187+
165188
# Export using both the native and EC .edata sections.
166189

167190
RUN: lld-link -machine:arm64x -dll -out:out-edata-both.dll arm64ec-func.obj arm64-func.obj \

0 commit comments

Comments
 (0)