Skip to content

Commit 648a827

Browse files
committed
[lld] select a default eflags for hexagon
Empty archives are apparently routine in linux kernel builds, so instead of asserting, we should handle this case with a sane default value.
1 parent caebb45 commit 648a827

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

lld/ELF/Arch/Hexagon.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,17 @@ Hexagon::Hexagon() {
6060
}
6161

6262
uint32_t Hexagon::calcEFlags() const {
63-
assert(!ctx.objectFiles.empty());
63+
static uint32_t DEFAULT_ARCH_REV = 0x60;
6464

6565
// The architecture revision must always be equal to or greater than
6666
// greatest revision in the list of inputs.
67-
uint32_t ret = 0;
67+
std::optional<uint32_t> ret;
6868
for (InputFile *f : ctx.objectFiles) {
6969
uint32_t eflags = cast<ObjFile<ELF32LE>>(f)->getObj().getHeader().e_flags;
70-
if (eflags > ret)
70+
if (!ret || eflags > *ret)
7171
ret = eflags;
7272
}
73-
return ret;
73+
return ret.value_or(DEFAULT_ARCH_REV);
7474
}
7575

7676
static uint32_t applyMask(uint32_t mask, uint32_t data) {

lld/test/ELF/hexagon-eflag.s

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@
55
# RUN: llvm-readelf -h %t3 | FileCheck %s
66
# Verify that the largest arch in the input list is selected.
77
# CHECK: Flags: 0x62
8+
9+
# RUN: llvm-ar rcsD %t4
10+
# RUN: ld.lld -m hexagonelf %t4 -o %t5
11+
# RUN: llvm-readelf -h %t5 | FileCheck --check-prefix=CHECK-EMPTYARCHIVE %s
12+
# CHECK-EMPTYARCHIVE: Flags: 0x60

0 commit comments

Comments
 (0)