Skip to content

Commit 550efd1

Browse files
author
Ash Dobrescu
committed
Make getEntryIDForSymbol() return optional and address review comments
1 parent 797b5b2 commit 550efd1

File tree

4 files changed

+13
-25
lines changed

4 files changed

+13
-25
lines changed

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,8 @@ class BinaryFunction {
650650
///
651651
/// Prefer to use BinaryContext::getFunctionForSymbol(EntrySymbol, &ID)
652652
/// instead of calling this function directly.
653-
uint64_t getEntryIDForSymbol(const MCSymbol *EntrySymbol) const;
653+
std::optional<uint64_t>
654+
getEntryIDForSymbol(const MCSymbol *EntrySymbol) const;
654655

655656
/// If the function represents a secondary split function fragment, set its
656657
/// parent fragment to \p BF.

bolt/lib/Core/BinaryContext.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2378,11 +2378,10 @@ BinaryFunction *BinaryContext::getFunctionForSymbol(const MCSymbol *Symbol,
23782378
const uint64_t Address = BF->getAddress() + Symbol->getOffset();
23792379
if (BF->isInConstantIsland(Address)) {
23802380
this->outs() << "BOLT-WARNING: symbol " << Symbol->getName()
2381-
<< " is in data region of function 0x"
2382-
<< Twine::utohexstr(BF->getAddress()) << ".\n";
2383-
return nullptr;
2381+
<< " is in data region of function " << BF->getOneName()
2382+
<< "(0x" << Twine::utohexstr(BF->getAddress()) << ").\n";
23842383
}
2385-
*EntryDesc = BF->getEntryIDForSymbol(Symbol);
2384+
*EntryDesc = BF->getEntryIDForSymbol(Symbol).value_or(0);
23862385
}
23872386

23882387
return BF;

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3855,7 +3855,8 @@ MCSymbol *BinaryFunction::getSymbolForEntryID(uint64_t EntryID) {
38553855
return nullptr;
38563856
}
38573857

3858-
uint64_t BinaryFunction::getEntryIDForSymbol(const MCSymbol *Symbol) const {
3858+
std::optional<uint64_t>
3859+
BinaryFunction::getEntryIDForSymbol(const MCSymbol *Symbol) const {
38593860
if (!isMultiEntry())
38603861
return 0;
38613862

@@ -3882,8 +3883,7 @@ uint64_t BinaryFunction::getEntryIDForSymbol(const MCSymbol *Symbol) const {
38823883
return NumEntries;
38833884
++NumEntries;
38843885
}
3885-
3886-
llvm_unreachable("symbol not found");
3886+
return std::nullopt;
38873887
}
38883888

38893889
bool BinaryFunction::forEachEntryPoint(EntryPointCallbackTy Callback) const {

bolt/test/AArch64/check-symbol-area.s

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,26 @@
1212
# CHECK-NOT: UNREACHABLE
1313

1414
// Now BOLT throws a warning and does not crash.
15-
# CHECK: BOLT-WARNING: symbol [[SYM:.*]] is in data region of function 0x{{.*}}.
15+
# CHECK: BOLT-WARNING: symbol third_block/1 is in data region of function first_block(0x{{[0-9a-f]+}}).
1616

1717
.text
1818
.global main
1919
main:
20-
stp x14, x15, [sp, -8]!
21-
mov x14, sp
22-
adrp x1, .test
23-
add x0, x1, :lo12:.test
20+
add x0, x1, x1
2421
bl first_block
2522
ret
2623

2724
.global first_block
2825
$d:
2926
first_block:
30-
stp x14, x15, [sp, -8]!
31-
mov x14, sp
27+
add x0, x1, x1
3228
bl second_block
3329
ret
3430
second_block:
35-
stp x14, x15, [sp, -8]!
36-
mov x14, sp
31+
add x0, x1, x1
3732
bl third_block
3833
ret
3934
$x:
4035
third_block:
41-
stp x14, x15, [sp, -8]!
42-
mov x14, sp
43-
adrp x1, .data
44-
add x0, x1, :lo12:.test
36+
add x0, x1, x1
4537
ret
46-
47-
.data
48-
.test:
49-
.string "test"

0 commit comments

Comments
 (0)