Skip to content

Commit f6575d5

Browse files
committed
Report an error if CREL contains addends for REL-type targets
Fixes #1430
1 parent bf1ec5a commit f6575d5

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/input-files.cc

+7-3
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,17 @@ static bool is_known_section_type(const ElfShdr<E> &shdr) {
242242
//
243243
// This function converts a CREL relocation table to a regular one.
244244
template <typename E>
245-
std::vector<ElfRel<E>> decode_crel(Context<E> &ctx, std::string_view contents) {
246-
u8 *p = (u8 *)contents.data();
245+
std::vector<ElfRel<E>> decode_crel(Context<E> &ctx, ObjectFile<E> &file,
246+
const ElfShdr<E> &shdr) {
247+
u8 *p = (u8 *)file.get_string(ctx, shdr).data();
247248
u64 hdr = read_uleb(&p);
248249
i64 nrels = hdr >> 3;
249250
bool is_rela = hdr & 0b100;
250251
i64 scale = hdr & 0b11;
251252

253+
if (is_rela && !E::is_rela)
254+
Fatal(ctx) << file << ": CREL with addends is not supported for " << E::name;
255+
252256
u64 offset = 0;
253257
i64 type = 0;
254258
i64 symidx = 0;
@@ -350,7 +354,7 @@ void ObjectFile<E>::initialize_sections(Context<E> &ctx) {
350354
}
351355
case SHT_CREL:
352356
decoded_crel.resize(i + 1);
353-
decoded_crel[i] = decode_crel(ctx, this->get_string(ctx, shdr));
357+
decoded_crel[i] = decode_crel(ctx, *this, shdr);
354358
break;
355359
case SHT_REL:
356360
case SHT_RELA:

test/crel.sh

100644100755
+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#!/bin/bash
22
. $(dirname $0)/common.inc
33

4+
# Currently, CREL is not supported on REL-type targets
5+
[ $MACHINE = arm ] && skip
6+
[ $MACHINE = i686 ] && skip
7+
48
[ "$CC" = cc ] || skip
59
clang -c -xc -o /dev/null /dev/null -Wa,--crel,--allow-experimental-crel || skip
610

0 commit comments

Comments
 (0)