Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,24 @@ class HexagonAsmBackend : public MCAsmBackend {
MCContext &Context = Asm.getContext();
auto &RF = cast<MCRelaxableFragment>(*Frags[K]);
auto &Inst = const_cast<MCInst &>(RF.getInst());

const bool WouldTraverseLabel = llvm::any_of(
Asm.symbols(), [&Asm, &RF, &Inst](MCSymbol const &sym) {
uint64_t Offset = 0;
const bool HasOffset = Asm.getSymbolOffset(sym, Offset);
const unsigned PacketSizeBytes =
HexagonMCInstrInfo::bundleSize(Inst) *
HEXAGON_INSTR_SIZE;
const bool OffsetPastSym =
Offset <= (Asm.getFragmentOffset(RF) + PacketSizeBytes);
return !sym.isVariable() && Offset != 0 && HasOffset &&
OffsetPastSym;
});
if (WouldTraverseLabel) {
Size = 0;
break;
}

while (Size > 0 &&
HexagonMCInstrInfo::bundleSize(Inst) < MaxPacketSize) {
MCInst *Nop = Context.createMCInst();
Expand Down
18 changes: 18 additions & 0 deletions llvm/test/MC/Hexagon/align-leb128.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# RUN: llvm-mc -triple=hexagon -filetype=obj %s | llvm-readelf -x .data - \
# RUN: | FileCheck %s --match-full-lines

# Illustrate the case when padding packets across labels also breaks leb128
# relocations. This happens because .align padding is inserted once at the
# very end of the section layout.
L1:
nop
L2:
.size L1, L2-L1
.align 16
nop
.data
.word L2-L1
.uleb128 L2-L1

# CHECK: Hex dump of section '.data':
# CHECK-NEXT: 0x00000000 04000000 04 .....
13 changes: 13 additions & 0 deletions llvm/test/MC/Hexagon/align.s
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,16 @@ r0 = vextract(v0, r0)
r1 = sub (##1, r1) }
.align 16
{ r0 = sub (#1, r0) }

# Don't search backwards to pad packets beyond a label:
{ r1 = add(r1, r0) }
# CHECK-NEXT: { r1 = add(r1,r0)
# CHECK-NOT: nop

post_label:
.align 16
# CHECK-LABEL: post_label
# CHECK-NEXT: { nop
# CHECK-NEXT: nop }
# CHECK-NEXT: { r1 = sub(#1,r1) }
{ r1 = sub(#1, r1) }