Skip to content

Commit 7379a19

Browse files
committed
[ELF] Replace PPC64 writeSequence static variables with bAlloc
to reduce global state.
1 parent 33ff9e4 commit 7379a19

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

lld/ELF/Arch/PPC64.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,13 @@ static bool addOptional(Ctx &ctx, StringRef name, uint64_t value,
265265
// If from is 14, write ${prefix}14: firstInsn; ${prefix}15:
266266
// firstInsn+0x200008; ...; ${prefix}31: firstInsn+(31-14)*0x200008; $tail
267267
// The labels are defined only if they exist in the symbol table.
268-
static void writeSequence(Ctx &ctx, MutableArrayRef<uint32_t> buf,
269-
const char *prefix, int from, uint32_t firstInsn,
270-
ArrayRef<uint32_t> tail) {
268+
static void writeSequence(Ctx &ctx, const char *prefix, int from,
269+
uint32_t firstInsn, ArrayRef<uint32_t> tail) {
271270
std::vector<Defined *> defined;
272271
char name[16];
273272
int first;
273+
const size_t size = 32 - from + tail.size();
274+
MutableArrayRef<uint32_t> buf(bAlloc(ctx).Allocate<uint32_t>(size), size);
274275
uint32_t *ptr = buf.data();
275276
for (int r = from; r < 32; ++r) {
276277
format("%s%d", prefix, r).snprint(name, sizeof(name));
@@ -310,22 +311,20 @@ static void writeSequence(Ctx &ctx, MutableArrayRef<uint32_t> buf,
310311
// significant enough to complicate our trunk implementation, so we take the
311312
// simple approach and synthesize .text sections providing the implementation.
312313
void elf::addPPC64SaveRestore(Ctx &ctx) {
313-
static uint32_t savegpr0[20], restgpr0[21], savegpr1[19], restgpr1[19];
314314
constexpr uint32_t blr = 0x4e800020, mtlr_0 = 0x7c0803a6;
315315

316316
// _restgpr0_14: ld 14, -144(1); _restgpr0_15: ld 15, -136(1); ...
317317
// Tail: ld 0, 16(1); mtlr 0; blr
318-
writeSequence(ctx, restgpr0, "_restgpr0_", 14, 0xe9c1ff70,
319-
{0xe8010010, mtlr_0, blr});
318+
writeSequence(ctx, "_restgpr0_", 14, 0xe9c1ff70, {0xe8010010, mtlr_0, blr});
320319
// _restgpr1_14: ld 14, -144(12); _restgpr1_15: ld 15, -136(12); ...
321320
// Tail: blr
322-
writeSequence(ctx, restgpr1, "_restgpr1_", 14, 0xe9ccff70, {blr});
321+
writeSequence(ctx, "_restgpr1_", 14, 0xe9ccff70, {blr});
323322
// _savegpr0_14: std 14, -144(1); _savegpr0_15: std 15, -136(1); ...
324323
// Tail: std 0, 16(1); blr
325-
writeSequence(ctx, savegpr0, "_savegpr0_", 14, 0xf9c1ff70, {0xf8010010, blr});
324+
writeSequence(ctx, "_savegpr0_", 14, 0xf9c1ff70, {0xf8010010, blr});
326325
// _savegpr1_14: std 14, -144(12); _savegpr1_15: std 15, -136(12); ...
327326
// Tail: blr
328-
writeSequence(ctx, savegpr1, "_savegpr1_", 14, 0xf9ccff70, {blr});
327+
writeSequence(ctx, "_savegpr1_", 14, 0xf9ccff70, {blr});
329328
}
330329

331330
// Find the R_PPC64_ADDR64 in .rela.toc with matching offset.

0 commit comments

Comments
 (0)