Skip to content

Commit 3fd4b31

Browse files
committed
Factor out pcrelOffset call
1 parent 245c582 commit 3fd4b31

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

lld/MachO/Arch/X86_64.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static constexpr std::array<RelocAttrs, 10> relocAttrsArray{{
6565
#undef B
6666
}};
6767

68-
static int pcrelOffset(uint8_t type) {
68+
static int getPcrelOffset(uint8_t type) {
6969
switch (type) {
7070
case X86_64_RELOC_SIGNED_1:
7171
return 1;
@@ -82,14 +82,15 @@ int64_t X86_64::getEmbeddedAddend(MemoryBufferRef mb, uint64_t offset,
8282
relocation_info rel) const {
8383
auto *buf = reinterpret_cast<const uint8_t *>(mb.getBufferStart());
8484
const uint8_t *loc = buf + offset + rel.r_address;
85+
int pcrelOffset = getPcrelOffset(rel.r_type);
8586

8687
switch (rel.r_length) {
8788
case 0:
88-
return *loc + pcrelOffset(rel.r_type);
89+
return *loc + pcrelOffset;
8990
case 2:
90-
return static_cast<int32_t>(read32le(loc)) + pcrelOffset(rel.r_type);
91+
return static_cast<int32_t>(read32le(loc)) + pcrelOffset;
9192
case 3:
92-
return read64le(loc) + pcrelOffset(rel.r_type);
93+
return read64le(loc) + pcrelOffset;
9394
default:
9495
llvm_unreachable("invalid r_length");
9596
}
@@ -98,7 +99,7 @@ int64_t X86_64::getEmbeddedAddend(MemoryBufferRef mb, uint64_t offset,
9899
void X86_64::relocateOne(uint8_t *loc, const Reloc &r, uint64_t value,
99100
uint64_t relocVA) const {
100101
if (r.pcrel) {
101-
uint64_t pc = relocVA + (1 << r.length) + pcrelOffset(r.type);
102+
uint64_t pc = relocVA + (1 << r.length) + getPcrelOffset(r.type);
102103
value -= pc;
103104
}
104105

0 commit comments

Comments
 (0)