Skip to content

Commit bf2c440

Browse files
committed
Refactor
1 parent abe7943 commit bf2c440

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

elf/arch-m68k.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ void InputSection<E>::scan_relocations(Context<E> &ctx) {
334334
case R_68K_TLS_LE8:
335335
break;
336336
default:
337-
Fatal(ctx) << *this << ": unknown relocation: " << rel;
337+
Error(ctx) << *this << ": unknown relocation: " << rel;
338338
}
339339
}
340340
}

elf/arch-ppc32.cc

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// support position-independent code (PIC) on PPC32.
1515
//
1616
// A position-independent function typically contains the following code
17-
// in its prologue to obtain its own own address:
17+
// in the prologue to obtain its own address:
1818
//
1919
// mflr r0 // save the current return address to %r0
2020
// bcl 20, 31, 4 // call the next instruction as if it were a function
@@ -26,17 +26,19 @@
2626
// constants. A PIC function usually computes its .got2+0x8000 and set it
2727
// to %r30. This scheme allows the function to access global objects
2828
// defined in the same input file with a single %r30-relative load/store
29-
// instructions with a 16-bit offset, given that the object file doesn't
29+
// instruction with a 16-bit offset, given that the object file doesn't
3030
// contain more than 65535 global objects.
3131
//
3232
// Since each object file has its own .got2, %r30 refers to different
33-
// places in a merged .got2 for two functions came from different input
34-
// files. Therefore, %r30 makes sense only within a single function.
33+
// places in a merged .got2 for two functions that are came from different
34+
// input files. Therefore, %r30 makes sense only within a single function.
3535
//
3636
// Technically, we can reuse a %r30 value in our PLT if we create a PLT
3737
// _for each input file_ (that's what GNU ld seems to be doing), but that
3838
// doesn't seems to worth its complexity. Our PLT simply doesn't rely on a
3939
// %r30 value.
40+
//
41+
// https://github.com/rui314/mold/wiki/ppc32-psabi.pdf
4042

4143
#include "mold.h"
4244

@@ -300,7 +302,7 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
300302
case R_PPC_PLTCALL:
301303
break;
302304
default:
303-
Fatal(ctx) << *this << ": apply_reloc_alloc relocation: " << rel;
305+
unreachable();
304306
}
305307

306308
#undef S
@@ -337,10 +339,14 @@ void InputSection<E>::apply_reloc_nonalloc(Context<E> &ctx, u8 *base) {
337339

338340
switch (rel.r_type) {
339341
case R_PPC_ADDR32:
340-
*(ub32 *)loc = S + A;
342+
if (std::optional<u64> val = get_tombstone(sym, frag))
343+
*(ub32 *)loc = *val;
344+
else
345+
*(ub32 *)loc = S + A;
341346
break;
342347
default:
343-
Fatal(ctx) << *this << ": apply_reloc_nonalloc: " << rel;
348+
Fatal(ctx) << *this << ": invalid relocation for non-allocated sections: "
349+
<< rel;
344350
}
345351

346352
#undef S
@@ -433,7 +439,7 @@ void InputSection<E>::scan_relocations(Context<E> &ctx) {
433439
case R_PPC_PLTCALL:
434440
break;
435441
default:
436-
Fatal(ctx) << *this << ": scan_relocations: " << rel;
442+
Error(ctx) << *this << ": unknown relocation: " << rel;
437443
}
438444
}
439445
}

elf/arch-ppc64v1.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
257257
case R_PPC64_TLSLD:
258258
break;
259259
default:
260-
Fatal(ctx) << *this << ": apply_reloc_alloc relocation: " << rel;
260+
unreachable();
261261
}
262262

263263
#undef S
@@ -316,7 +316,8 @@ void InputSection<E>::apply_reloc_nonalloc(Context<E> &ctx, u8 *base) {
316316
*(ub64 *)loc = S + A - ctx.dtp_addr;
317317
break;
318318
default:
319-
Fatal(ctx) << *this << ": apply_reloc_nonalloc: " << rel;
319+
Fatal(ctx) << *this << ": invalid relocation for non-allocated sections: "
320+
<< rel;
320321
}
321322

322323
#undef S
@@ -403,7 +404,7 @@ void InputSection<E>::scan_relocations(Context<E> &ctx) {
403404
case R_PPC64_DTPREL16_LO:
404405
break;
405406
default:
406-
Fatal(ctx) << *this << ": scan_relocations: " << rel;
407+
Error(ctx) << *this << ": unknown relocation: " << rel;
407408
}
408409
}
409410
}

elf/arch-ppc64v2.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ void EhFrameSection<E>::apply_reloc(Context<E> &ctx, const ElfRel<E> &rel,
143143

144144
static u64 get_local_entry_offset(Context<E> &ctx, Symbol<E> &sym) {
145145
i64 val = sym.esym().ppc_local_entry;
146+
assert(val <= 7);
146147
if (val == 0 || val == 1)
147148
return 0;
148149
if (val == 7)
@@ -275,7 +276,7 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
275276
case R_PPC64_TLSLD:
276277
break;
277278
default:
278-
Fatal(ctx) << *this << ": apply_reloc_alloc relocation: " << rel;
279+
unreachable();
279280
}
280281

281282
#undef S
@@ -334,7 +335,8 @@ void InputSection<E>::apply_reloc_nonalloc(Context<E> &ctx, u8 *base) {
334335
*(ul64 *)loc = S + A - ctx.dtp_addr;
335336
break;
336337
default:
337-
Fatal(ctx) << *this << ": apply_reloc_nonalloc: " << rel;
338+
Fatal(ctx) << *this << ": invalid relocation for non-allocated sections: "
339+
<< rel;
338340
}
339341

340342
#undef S
@@ -412,7 +414,7 @@ void InputSection<E>::scan_relocations(Context<E> &ctx) {
412414
case R_PPC64_DTPREL16_LO:
413415
break;
414416
default:
415-
Fatal(ctx) << *this << ": scan_relocations: " << rel;
417+
Error(ctx) << *this << ": unknown relocation: " << rel;
416418
}
417419
}
418420
}

0 commit comments

Comments
 (0)