Skip to content

Commit 0172f22

Browse files
committed
Refactor
1 parent 418d4ff commit 0172f22

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

src/arch-arm32.cc

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ i64 get_addend(u8 *loc, const ElfRel<E> &rel) {
5757
case R_ARM_TLS_IE32:
5858
case R_ARM_TLS_LE32:
5959
case R_ARM_TLS_GOTDESC:
60+
case R_ARM_TARGET1:
6061
case R_ARM_TARGET2:
6162
return (il32)*arm;
6263
case R_ARM_THM_JUMP8:
@@ -181,6 +182,7 @@ void write_addend(u8 *loc, i64 val, const ElfRel<E> &rel) {
181182
case R_ARM_TLS_IE32:
182183
case R_ARM_TLS_LE32:
183184
case R_ARM_TLS_GOTDESC:
185+
case R_ARM_TARGET1:
184186
case R_ARM_TARGET2:
185187
*(ul32 *)loc = val;
186188
break;
@@ -315,6 +317,7 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
315317

316318
switch (rel.r_type) {
317319
case R_ARM_ABS32:
320+
case R_ARM_TARGET1:
318321
break;
319322
case R_ARM_REL32:
320323
*(ul32 *)loc = S + A - P;
@@ -644,6 +647,7 @@ void InputSection<E>::scan_relocations(Context<E> &ctx) {
644647
check_tlsle(ctx, sym, rel);
645648
break;
646649
case R_ARM_ABS32:
650+
case R_ARM_TARGET1:
647651
case R_ARM_MOVT_ABS:
648652
case R_ARM_THM_MOVT_ABS:
649653
case R_ARM_REL32:

src/input-files.cc

-10
Original file line numberDiff line numberDiff line change
@@ -898,16 +898,6 @@ void ObjectFile<E>::parse(Context<E> &ctx) {
898898
initialize_sections(ctx);
899899
initialize_symbols(ctx);
900900
sort_relocations(ctx);
901-
902-
// R_ARM_TARGET1 is typically used for entries in .init_array and may
903-
// be interpreted as REL32 or ABS32 depending on the target.
904-
// All targets we support handle it as if it were a ABS32.
905-
if constexpr (is_arm32<E>)
906-
for (std::unique_ptr<InputSection<E>> &isec : sections)
907-
if (isec && isec->is_alive)
908-
for (ElfRel<E> &r : isec->get_rels(ctx))
909-
if (r.r_type == R_ARM_TARGET1)
910-
r.r_type = R_ARM_ABS32;
911901
}
912902

913903
// Symbols with higher priorities overwrites symbols with lower priorities.

src/output-chunks.cc

+11-1
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,16 @@ static AbsRelKind get_abs_rel_kind(Context<E> &ctx, Symbol<E> &sym) {
10571057
return ABS_REL_DYNREL;
10581058
}
10591059

1060+
template <typename E>
1061+
static bool is_absrel(const ElfRel<E> &r) {
1062+
// On ARM32, R_ARM_TARGET1 is typically used for entries in .init_array
1063+
// and is interpreted as either ABS32 or REL32 depending on the target.
1064+
// All targets we support handle it as if it were a ABS32.
1065+
if constexpr (is_arm32<E>)
1066+
return r.r_type == E::R_ABS || r.r_type == R_ARM_TARGET1;
1067+
return r.r_type == E::R_ABS;
1068+
}
1069+
10601070
// Scan word-size absolute relocations (e.g. R_X86_64_64). This is
10611071
// separated from scan_relocations() because only such relocations can
10621072
// be promoted to dynamic relocations.
@@ -1068,7 +1078,7 @@ void OutputSection<E>::scan_abs_relocations(Context<E> &ctx) {
10681078
tbb::parallel_for((i64)0, (i64)members.size(), [&](i64 i) {
10691079
InputSection<E> *isec = members[i];
10701080
for (const ElfRel<E> &r : isec->get_rels(ctx))
1071-
if (r.r_type == E::R_ABS)
1081+
if (is_absrel(r))
10721082
shards[i].push_back(AbsRel<E>{isec, r.r_offset, isec->file.symbols[r.r_sym],
10731083
get_addend(*isec, r)});
10741084
});

0 commit comments

Comments
 (0)