Skip to content

Commit 186272a

Browse files
committed
Handle R_ARM_TARGET1 as a synonym for R_ARM_ABS32
This fixes a regression introduced in 431fc39. Fixes #1351
1 parent 5fcbf25 commit 186272a

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

src/output-chunks.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1109,11 +1109,21 @@ template <typename E>
11091109
void OutputSection<E>::scan_abs_relocations(Context<E> &ctx) {
11101110
std::vector<std::vector<AbsRel<E>>> shards(members.size());
11111111

1112+
auto is_absrel = [](const ElfRel<E> &r) {
1113+
// R_ARM_TARGET1 is typically used for entries in .init_array and can
1114+
// be interpreted as REL32 or ABS32 depending on the target.
1115+
// All targets we support handle it as if it were a synonym for ABS32.
1116+
if constexpr (is_arm32<E>)
1117+
if (r.r_type == R_ARM_TARGET1)
1118+
return true;
1119+
return r.r_type == E::R_ABS;
1120+
};
1121+
11121122
// Collect all word-size absolute relocations
11131123
tbb::parallel_for((i64)0, (i64)members.size(), [&](i64 i) {
11141124
InputSection<E> *isec = members[i];
11151125
for (const ElfRel<E> &r : isec->get_rels(ctx))
1116-
if (r.r_type == E::R_ABS)
1126+
if (is_absrel(r))
11171127
shards[i].push_back(AbsRel<E>{isec, r.r_offset, isec->file.symbols[r.r_sym],
11181128
get_addend(*isec, r)});
11191129
});

test/arch-arm-target1.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
. $(dirname $0)/common.inc
3+
4+
cat <<EOF | $CC -c -o $t/a.o -xassembler -
5+
.globl foo
6+
.data
7+
foo:
8+
.word bar(TARGET1)
9+
EOF
10+
11+
cat <<EOF | $CC -fPIC -c -o $t/b.o -xc -
12+
#include <stdio.h>
13+
extern char *foo;
14+
char bar[] = "Hello world";
15+
int main() { printf("%s\n", foo); }
16+
EOF
17+
18+
$CC -B. -o $t/exe -pie $t/a.o $t/b.o
19+
$QEMU $t/exe | grep -q 'Hello world'

0 commit comments

Comments
 (0)