Skip to content

Commit 21276fd

Browse files
authored
[MC] Don't treat altentry symbols as atoms
The current `setAtom` is inaccurate: a `.alt_entry` label can also be recognized as an atom. This is mostly benign, but might cause two locations only separated by an `.alt_entry` to have different atoms. https://reviews.llvm.org/D153167 changed a `evaluateKnownAbsolute` to `evaluateAsAbsolute` and would not fold `A-B` even if they are only separated by a `.alt_entry` label, leading to a spurious error `invalid CFI advance_loc expression`. The fix is similar to #82268: add a special case for `.alt_entry`. Fix #97116 Pull Request: #97479
1 parent 9ed4b17 commit 21276fd

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

llvm/lib/MC/MCMachOStreamer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ void MCMachOStreamer::finishImpl() {
508508
DenseMap<const MCFragment *, const MCSymbol *> DefiningSymbolMap;
509509
for (const MCSymbol &Symbol : getAssembler().symbols()) {
510510
if (getAssembler().isSymbolLinkerVisible(Symbol) && Symbol.isInSection() &&
511-
!Symbol.isVariable()) {
511+
!Symbol.isVariable() && !cast<MCSymbolMachO>(Symbol).isAltEntry()) {
512512
// An atom defining symbol should never be internal to a fragment.
513513
assert(Symbol.getOffset() == 0 &&
514514
"Invalid offset in atom defining symbol!");

llvm/test/MC/MachO/cfi-advance-loc-err.s

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ _foo:
99
subq $8, %rsp
1010
.cfi_adjust_cfa_offset 8
1111

12+
.alt_entry _bar
13+
_bar: # alt_entry label can appear here as it is not an atom
14+
addq $8, %rsp
15+
.cfi_adjust_cfa_offset -8
16+
1217
tmp0: # non-private label cannot appear here
1318
addq $8, %rsp
1419
# CHECK: :[[#@LINE+1]]:3: error: invalid CFI advance_loc expression

0 commit comments

Comments
 (0)