File tree Expand file tree Collapse file tree 6 files changed +41
-2
lines changed
x86_64/linux/EmulationSupport Expand file tree Collapse file tree 6 files changed +41
-2
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,8 @@ class x86_64LinkDriver : public GnuLdDriver {
4040
4141 virtual ~x86_64LinkDriver () {}
4242
43+ static bool isValidEmulation (llvm::StringRef Emulation );
44+
4345 // Main entry point.
4446 int link (llvm::ArrayRef<const char *> Args,
4547 llvm::ArrayRef<llvm::StringRef> ELDFlagsArgs) override ;
Original file line number Diff line number Diff line change 1111#include " eld/Driver/GnuLdDriver.h"
1212#include " eld/Driver/HexagonLinkDriver.h"
1313#include " eld/Driver/RISCVLinkDriver.h"
14+ #include " eld/Driver/x86_64LinkDriver.h"
1415#include " eld/PluginAPI/DiagnosticEntry.h"
1516#include " eld/Support/Memory.h"
1617#include " eld/Support/TargetRegistry.h"
@@ -182,6 +183,10 @@ Driver::getFlavorAndTripleFromLinkCommand(llvm::ArrayRef<const char *> Args) {
182183 else if (EmulationTriple.getArch () == llvm::Triple::aarch64)
183184 F = Flavor::AArch64;
184185 }
186+ #endif
187+ #if defined(ELD_ENABLE_TARGET_X86_64)
188+ if (x86_64LinkDriver::isValidEmulation (Emulation))
189+ F = Flavor::x86_64;
185190#endif
186191 if (F == Flavor::Invalid)
187192 return std::make_unique<eld::DiagnosticEntry>(
Original file line number Diff line number Diff line change @@ -161,3 +161,8 @@ template <class T>
161161bool x86_64LinkDriver::processLLVMOptions (llvm::opt::InputArgList &Args) {
162162 return GnuLdDriver::processLLVMOptions<T>(Args);
163163}
164+
165+
166+ bool x86_64LinkDriver::isValidEmulation (llvm::StringRef Emulation){
167+ return Emulation == " elf_x86_64" || Emulation == " elf_amd64" ;
168+ }
Original file line number Diff line number Diff line change @@ -277,11 +277,11 @@ if config.test_target == 'Hexagon':
277277
278278if config .test_target == 'X86' :
279279 config .march = ''
280- clang = 'clang'
280+ clang = 'clang -target x86_64-linux-gnu '
281281 clangxx = 'clang++'
282282 llvmmc = 'llvm-mc'
283283 readelf = 'llvm-readelf'
284- link = 'x86_64-link '
284+ link = 'ld.eld -m elf_x86_64 '
285285 ar = 'llvm-ar'
286286 nm = 'llvm-nm'
287287 objdump = 'llvm-objdump'
Original file line number Diff line number Diff line change 1+ #---x86_64_Emulation.test----------------- Executable --------------------#
2+
3+ BEGIN_COMMENT
4+ # Test x86_64 emulation support in eld
5+ # This test verifies that eld correctly handles the -m elf_x86_64 emulation flag.
6+ # It compiles a minimal C program with a custom _start() that performs a syscall
7+ # to exit with code 5. The program is linked using eld with --image-base.
8+ #END_COMMENT
9+
10+ #START_TEST
11+ RUN: %clang %clangopts -c %p/Inputs/1.c -o %t.1.o
12+ RUN: %link %linkopts -o %t.1.out %t.1.o --image-base=0x400000
13+ RUN: %t.1.out; echo $? > %t.code
14+ RUN: %filecheck --input-file=%t.code %s --check-prefix=EXITCODE
15+ EXITCODE: 5
16+ #END_TEST
Original file line number Diff line number Diff line change 1+ void _start () {
2+ long u = 5 ;
3+ asm (
4+ "movq $60, %%rax\n"
5+ "movq %0, %%rdi\n"
6+ "syscall\n"
7+ :
8+ : "r" (u )
9+ : "%rax" , "%rdi"
10+ );
11+ }
You can’t perform that action at this time.
0 commit comments