Skip to content

Commit 2a4e4c3

Browse files
committed
[hexagon] Add linux emulation
Add hexagonlinux emulation, and enable hexagon linux tests. This change also removes the special casing for hexagon-linux-link/x86_64-link. Signed-off-by: Shankar Easwaran <seaswara@qti.qualcomm.com>
1 parent 1a118f8 commit 2a4e4c3

126 files changed

Lines changed: 241 additions & 232 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

include/eld/Driver/HexagonLinkDriver.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ class HexagonLinkDriver : public GnuLdDriver {
7777

7878
static bool isValidEmulation(llvm::StringRef Emulation);
7979

80+
static std::optional<llvm::Triple>
81+
ParseEmulation(std::string pEmulation, eld::DiagnosticEngine *DiagEngine);
82+
8083
static std::string getInferredArch(llvm::StringRef Emulation) {
8184
return "hexagon";
8285
}

lib/LinkerWrapper/HexagonLinkDriver.cpp

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,41 @@ bool HexagonLinkDriver::createInputActions(
207207

208208
template <class T>
209209
bool HexagonLinkDriver::processTargetOptions(llvm::opt::InputArgList &Args) {
210-
return GnuLdDriver::processTargetOptions<T>(Args);
210+
bool result = GnuLdDriver::processTargetOptions<T>(Args);
211+
std::string emulation = Config.options().getEmulation().str();
212+
// If a specific emulation was requested, apply it now.
213+
if (!emulation.empty()) {
214+
llvm::Triple TheTriple = Config.targets().triple();
215+
std::optional<Triple> OptEmulationTriple =
216+
ParseEmulation(emulation, Config.getDiagEngine());
217+
// Report invalid emulation error for unknown emulation.
218+
if (!OptEmulationTriple) {
219+
DiagEngine->raise(eld::Diag::err_invalid_emulation) << emulation;
220+
return false;
221+
}
222+
Triple EmulationTriple = OptEmulationTriple.value();
223+
if (EmulationTriple.getArch() != Triple::UnknownArch)
224+
TheTriple.setArch(EmulationTriple.getArch());
225+
if (EmulationTriple.getOS() != Triple::OSType::UnknownOS)
226+
TheTriple.setOS(EmulationTriple.getOS());
227+
if (EmulationTriple.getEnvironment() != Triple::UnknownEnvironment)
228+
TheTriple.setEnvironment(EmulationTriple.getEnvironment());
229+
Config.targets().setTriple(TheTriple);
230+
}
231+
return result;
232+
}
233+
234+
std::optional<Triple>
235+
HexagonLinkDriver::ParseEmulation(std::string pEmulation,
236+
eld::DiagnosticEngine *DiagEngine) {
237+
std::optional<Triple> result =
238+
StringSwitch<std::optional<Triple>>(pEmulation)
239+
.Case("hexagonlinux", Triple("hexagon", "", "linux", "gnu"))
240+
.Cases({"hexagonelf", "v68", "v69", "v71", "v71t", "v73", "v75",
241+
"v77", "v79", "v81", "v83", "v85", "v87", "v89", "v91"},
242+
Triple("hexagon", "", "", ""))
243+
.Default(std::nullopt);
244+
return result;
211245
}
212246

213247
template <class T>
@@ -217,7 +251,7 @@ bool HexagonLinkDriver::processLLVMOptions(llvm::opt::InputArgList &Args) {
217251

218252
bool HexagonLinkDriver::isValidEmulation(llvm::StringRef Emulation) {
219253
return llvm::StringSwitch<bool>(Emulation)
220-
.Cases({"hexagonelf", "v68", "v69", "v71", "v71t"}, true)
254+
.Cases({"hexagonelf", "hexagonlinux", "v68", "v69", "v71", "v71t"}, true)
221255
.Cases({"v73", "v75", "v77", "v79", "v81", "v83", "v85", "v87", "v89",
222256
"v91"},
223257
true)

lib/Target/Hexagon/HexagonEmulation.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,23 @@ static bool ELDEmulateHexagonELF(LinkerScript &pScript, LinkerConfig &pConfig) {
2323
pConfig.targets().setBitClass(32);
2424
llvm::StringRef Emulation = pConfig.options().getEmulation();
2525
if (!Emulation.empty()) {
26-
llvm::StringRef flag = llvm::StringSwitch<StringRef>(Emulation)
27-
.Cases({"v68", "hexagonelf"}, "hexagonv68")
28-
.Case("v69", "hexagonv69")
29-
.Case("v71", "hexagonv71")
30-
.Case("v71t", "hexagonv71t")
31-
.Case("v73", "hexagonv73")
32-
.Case("v75", "hexagonv75")
33-
.Case("v77", "hexagonv77")
34-
.Case("v79", "hexagonv79")
35-
.Case("v81", "hexagonv81")
36-
.Case("v83", "hexagonv83")
37-
.Case("v85", "hexagonv85")
38-
.Case("v87", "hexagonv87")
39-
.Case("v89", "hexagonv89")
40-
.Case("v91", "hexagonv91")
41-
.Default("invalid");
26+
llvm::StringRef flag =
27+
llvm::StringSwitch<StringRef>(Emulation)
28+
.Cases({"v68", "hexagonelf", "hexagonlinux"}, "hexagonv68")
29+
.Case("v69", "hexagonv69")
30+
.Case("v71", "hexagonv71")
31+
.Case("v71t", "hexagonv71t")
32+
.Case("v73", "hexagonv73")
33+
.Case("v75", "hexagonv75")
34+
.Case("v77", "hexagonv77")
35+
.Case("v79", "hexagonv79")
36+
.Case("v81", "hexagonv81")
37+
.Case("v83", "hexagonv83")
38+
.Case("v85", "hexagonv85")
39+
.Case("v87", "hexagonv87")
40+
.Case("v89", "hexagonv89")
41+
.Case("v91", "hexagonv91")
42+
.Default("invalid");
4243
if (flag == "deprecated") {
4344
pConfig.raise(Diag::deprecated_emulation)
4445
<< pConfig.options().getEmulation();

test/Hexagon/linux/BssLinkOrder/BssLinkOrder.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ RUN: %clang %clangopts -c %clangg0opts %p/Inputs/1.c -o %t1.o
22
RUN: %clang %clangopts -c %clangg0opts %p/Inputs/2.c -o %t2.o
33
RUN: %clang %clangopts -c %clangg0opts %p/Inputs/3.c -o %t3.o
44
RUN: %clang %clangopts -c %clangg0opts %p/Inputs/4.c -o %t4.o
5-
RUN: %link %linkopts %linkg0opts %t1.o %t2.o %t3.o %t4.o -o %t.out
5+
RUN: %link %emulation %linkopts %linkg0opts %t1.o %t2.o %t3.o %t4.o -o %t.out
66
RUN: %nm -n %t.out | %filecheck %s
77

88
#CHECK: B b
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Check that the .comment section is not garbage collected.
22
RUN: %clang %clangopts -c %p/Inputs/1.s -o %t1.o
3-
RUN: %link %linkopts %t1.o -o %t2.out -e main --gc-sections
3+
RUN: %link %emulation %linkopts %t1.o -o %t2.out -e main --gc-sections
44
RUN: %readelf -S %t2.out | %filecheck %s
55

66
#CHECK: .comment

test/Hexagon/linux/CommonsGC/CommonsGC.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
RUN: %clang %clangopts -c -ffunction-sections -fdata-sections %p/Inputs/1.c -o %t1.o
2-
RUN: %link %linkopts %t1.o -o %t.out --gc-sections --entry=main 2>&1
2+
RUN: %link %emulation %linkopts %t1.o -o %t.out --gc-sections --entry=main 2>&1
33
RUN: %readelf -s %t.out | %grep 'common' | %filecheck %s
44

55
#CHECK: 1 OBJECT GLOBAL DEFAULT 2 commonChar

test/Hexagon/linux/CommonsGCSharedLib/CommonsGCSharedLib.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
RUN: %clang %clangopts -c -ffunction-sections -fdata-sections %p/Inputs/1.c -fpic -o %t1.o
2-
RUN: %link %linkopts %t1.o -o %t.out -dy -shared --gc-sections --entry=main 2>&1
2+
RUN: %link %emulation %linkopts %t1.o -o %t.out -dy -shared --gc-sections --entry=main 2>&1
33
RUN: %readelf -s %t.out | %filecheck %s
44

55
#CHECK-DAG: 4 OBJECT GLOBAL DEFAULT 9 commonInt

test/Hexagon/linux/CommonsGnuHash/CommonsGnuHash.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#START_TEST
1010

1111
RUN: %clang %clangopts -c -fpic %p/Inputs/1.c -o %t.o
12-
RUN: %link %linkopts -shared -hash-style=gnu -o %t.so %t.o
12+
RUN: %link %emulation %linkopts -shared -hash-style=gnu -o %t.so %t.o
1313
RUN: %readelf -I %t.so
1414

1515
CHECK: Histogram for `.gnu.hash' bucket list length (total of 3 buckets):

test/Hexagon/linux/CrefTable/CrefTable.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
RUN: %clang %clangopts -c -ffunction-sections -fdata-sections %p/Inputs/1.c -o %t1.o
22
RUN: %clang %clangopts -c -ffunction-sections -fdata-sections %p/Inputs/2.c -o %t2.o
33
RUN: %clang %clangopts -c -ffunction-sections -fdata-sections %p/Inputs/3.c -o %t3.o
4-
RUN: %link %linkopts %t1.o %t2.o %t3.o --cref -o %t.out --gc-sections --entry=main | %filecheck %s
4+
RUN: %link %emulation %linkopts %t1.o %t2.o %t3.o --cref -o %t.out --gc-sections --entry=main | %filecheck %s
55

66
#CHECK: bar {{.*tmp2.o}}
77
#CHECK: {{.*tmp3.o}}

test/Hexagon/linux/DebugRelocs/debugRelocs.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Check that Debug sections are fixed up properly.
22
RUN: %clang %clangopts -c %p/Inputs/crap.c -o %t1.o -g
33
RUN: %clang %clangopts -c %p/Inputs/hello.c -o %t2.o -g
4-
RUN: %link %linkopts %t1.o %t2.o -o %t.out --noinhibit-exec
4+
RUN: %link %emulation %linkopts %t1.o %t2.o -o %t.out --noinhibit-exec
55
RUN: %dwarfdump -debug-info %t.out | %filecheck %s
66

77
#CHECK: DW_AT_producer ("{{.*}}{{[cC]}}lang

0 commit comments

Comments
 (0)