This is an archive of the discontinued LLVM Phabricator instance.

[ELF2] Add a base set of PPC64 relocations
ClosedPublic

Authored by hfinkel on Oct 8 2015, 10:05 AM.

Details

Reviewers
ruiu
rafael
Summary

This is mostly an adaptation of the code in LLVM's lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp, and handles a sufficient number of relocations to link a 'hello world' program on big-Endian PPC64/Linux (ELF v1 ABI) (and said program will even run when a few later patches are also applied).

This is obviously still missing test cases; I'm working on those. Other feedback, and suggestions on which tests to emulate, is certainly appreciated.

Diff Detail

Event Timeline

hfinkel updated this revision to Diff 36870.Oct 8 2015, 10:05 AM
hfinkel retitled this revision from to [ELF2] Add a base set of PPC64 relocations.
hfinkel updated this object.
hfinkel added reviewers: ruiu, rafael.
hfinkel added a project: lld.
hfinkel added a subscriber: llvm-commits.
ruiu added inline comments.Oct 8 2015, 10:38 AM
ELF/Target.cpp
213

I'm not entirely sure, but the capitalization rule is usually applyPPCLo (not applyPPClo), no?

213–237

No need for inline. Compilers should take care of them.

215

Arguments must start with uppercase, so Value. But I prefer just V, so that we can write these functions one line.

219

No space before '('

249–250

I wouldn't write zeros beforehand. Instead, you can add as many "0, 0 , 0, ..." as you want at end of Insts to fill the entire space with zeros.

255

Remove this blank line.

264–278

I wouldn't construct Insts. Instead I'd do

write32be(Buf, 0xf810000u); // std %r2 ...
write32be(Buf + 4, 0x3d62000u | apply...)
write32be(Buf + 8, ...
296–300
if (Type != R_PPC64_REL24)
  return false;
return S.isShared() || (S....
304

BaseAddr -> Base

308

Rename Addend -> A, just like the ELF spec.

323

Offset -> Off

326–346

This switch statement enclosed with if-else-if looks a bit weird. Can you remove outer if and just use switch instead?

343–346

You want to move this piece of code just after "uint8_t *Loc = Buf + Offset;" to return early.

368

This style is not in line with others. Please don't put break after }

388

If you can trigger this assertion by giving broken object files, this shouldn't be an assert() but an error().

390

All variable must starts with uppercase.

423–427

Generally we have lots of very similar expressions to calculate relocation values, we want to write them down as simple as possible. So I don't want to use descriptive names for each temporary variables. Please use one-letter variables or don't use variables at all. For example, I'd write this as

int32_t V = int32(SymVA - Base + Off + A);
if (SignExtend32<32>(V) != V)
  error(...)
write32be(Loc, V);

(By the way, the above error check seems odd. It would never fail, no?)

430–432
write64be(Loc, SymVA - BaseAddr - Offset + Addend);
hfinkel marked 14 inline comments as done.Oct 9 2015, 11:28 PM
hfinkel added inline comments.
ELF/Target.cpp
213

Done.

213–237

Done.

215

Done.

219

Done.

249–250

Done.

255

Done.

264–278

Done.

296–300

Done.

304

BaseAddr is consistent with the names used by the other targets (we can certainly rename them all as a separate change).

308

Done.

323

Done.

326–346

It is done this way to share the addend-adjustment logic. Early-return: done.

368

Done.

388

Done.

390

Done.

423–427

Done.

You're right (I copied these checks from RuntimeDyldELF.cpp, and I should fix them up there as well).

430–432

I've changed everything to use similar short variable names to those that AArch64 uses.

ruiu edited edge metadata.Oct 10 2015, 8:55 AM

Can you upload the new patch? Thanks!

hfinkel marked 14 inline comments as done.Oct 10 2015, 8:59 AM
In D13562#264243, @ruiu wrote:

Can you upload the new patch? Thanks!

Yes; I'm working on some regression tests now.

hfinkel updated this revision to Diff 37029.Oct 10 2015, 10:10 AM
hfinkel edited edge metadata.

Updated to reflect reviewer comments and add a regression test.

ruiu added a comment.Oct 10 2015, 10:46 AM

Can you upload the new patch? Thanks!

ELF/Target.cpp
247

Add a blank line before this line.

247

This class does not use any members of the class, so let's make it a static non-member function.

247

Blank line.

257

Drop 'u' suffix.

260–261

Can this fit in one line if you use a shorter name for EntryOffset?

280

Blank line.

295

Blank line.

341–346

Write like this to remove the outer if.

case R_PPC64_TOC16: Type = R_PPC64_ADDR16; A -= getTocBase(); break;
case ...
355

(R) & ~3 -> R & ~3

357

You don't need {} here. {} is used in switch-case to create a new scope for local variables, but you didn't define any in this {}.

364

Ditto

379

Remove {}

383

Ditto

387

Ditto

388

*(L + 3) -> L[3]

393

Ditto

406

Ditto

410

Ditto

hfinkel updated this revision to Diff 37067.Oct 11 2015, 3:44 PM

Addressed review comments.

ruiu accepted this revision.Oct 11 2015, 3:57 PM
ruiu edited edge metadata.

LGTM with nits. Thank you for your work for PPC64!

ELF/Target.cpp
225

You can remove &0xffff because least significant 48 bits are already 0.

228

Ditto

This revision is now accepted and ready to land.Oct 11 2015, 3:57 PM
hfinkel closed this revision.Oct 12 2015, 1:58 PM

r250101, thanks!