return false;
}
+ // UseCodeAlign - Return true if a .align directive should use
+ // "optimized nops" to fill instead of 0s.
+ virtual bool UseCodeAlign() const = 0;
+
static bool classof(const MCSection *) { return true; }
};
virtual void PrintSwitchToSection(const MCAsmInfo &MAI,
raw_ostream &OS) const;
+ virtual bool UseCodeAlign() const;
static bool classof(const MCSection *S) {
return S->getVariant() == SV_COFF;
void PrintSwitchToSection(const MCAsmInfo &MAI,
raw_ostream &OS) const;
-
+ virtual bool UseCodeAlign() const;
+
/// isBaseAddressKnownZero - We know that non-allocatable sections (like
/// debug info) have a base of zero.
virtual bool isBaseAddressKnownZero() const {
virtual void PrintSwitchToSection(const MCAsmInfo &MAI,
raw_ostream &OS) const;
+ virtual bool UseCodeAlign() const;
static bool classof(const MCSection *S) {
return S->getVariant() == SV_MachO;
// Check whether we should use optimal code alignment for this .align
// directive.
- //
- // FIXME: This should be using a target hook.
- bool UseCodeAlign = false;
- if (const MCSectionMachO *S = dyn_cast<MCSectionMachO>(
- getStreamer().getCurrentSection()))
- UseCodeAlign = S->hasAttribute(MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS);
+ bool UseCodeAlign = getStreamer().getCurrentSection()->UseCodeAlign();
if ((!HasFillExpr || Lexer.getMAI().getTextAlignFillValue() == FillExpr) &&
ValueSize == 1 && UseCodeAlign) {
getStreamer().EmitCodeAlignment(Alignment, MaxBytesToFill);
}
}
}
+
+bool MCSectionCOFF::UseCodeAlign() const {
+ return getKind().isText();
+}
OS << '\n';
}
+bool MCSectionELF::UseCodeAlign() const {
+ return getFlags() & MCSectionELF::SHF_EXECINSTR;
+}
+
// HasCommonSymbols - True if this section holds common symbols, this is
// indicated on the ELF object file by a symbol with SHN_COMMON section
// header index.
OS << '\n';
}
+bool MCSectionMachO::UseCodeAlign() const {
+ return hasAttribute(MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS);
+}
+
/// StripSpaces - This removes leading and trailing spaces from the StringRef.
static void StripSpaces(StringRef &Str) {
while (!Str.empty() && isspace(Str[0]))
return "";
}
-
OS << '\n';
}
+
+bool PIC16Section::UseCodeAlign() const {
+ return isCODE_Type();
+}
virtual void PrintSwitchToSection(const MCAsmInfo &MAI,
raw_ostream &OS) const;
+ virtual bool UseCodeAlign() const;
+
static bool classof(const MCSection *S) {
return S->getVariant() == SV_PIC16;
}
--- /dev/null
+// RUN: llvm-mc -filetype=obj -triple i686-pc-win32 %s -o %t
+// RUN: coff-dump.py %abs_tmp | FileCheck %s
+
+// Test that we get optimal nops in text
+ .text
+f0:
+ .long 0
+ .align 8, 0x90
+ .long 0
+ .align 8
+
+// But not in another section
+ .data
+ .long 0
+ .align 8, 0x90
+ .long 0
+ .align 8
+
+//CHECK: Name = .text
+//CHECK-NEXT: VirtualSize
+//CHECK-NEXT: VirtualAddress
+//CHECK-NEXT: SizeOfRawData = 16
+//CHECK-NEXT: PointerToRawData
+//CHECK-NEXT: PointerToRelocations
+//CHECK-NEXT: PointerToLineNumbers
+//CHECK-NEXT: NumberOfRelocations
+//CHECK-NEXT: NumberOfLineNumbers
+//CHECK-NEXT: Charateristics = 0x400001
+//CHECK-NEXT: IMAGE_SCN_ALIGN_8BYTES
+//CHECK-NEXT: SectionData =
+//CHECK-NEXT: 00 00 00 00 0F 1F 40 00 - 00 00 00 00 0F 1F 40 00
+
+//CHECK: Name = .data
+//CHECK-NEXT: VirtualSize
+//CHECK-NEXT: VirtualAddress
+//CHECK-NEXT: SizeOfRawData = 16
+//CHECK-NEXT: PointerToRawData
+//CHECK-NEXT: PointerToRelocations
+//CHECK-NEXT: PointerToLineNumbers
+//CHECK-NEXT: NumberOfRelocations
+//CHECK-NEXT: NumberOfLineNumbers
+//CHECK-NEXT: Charateristics = 0x400001
+//CHECK-NEXT: IMAGE_SCN_ALIGN_8BYTES
+//CHECK-NEXT: SectionData =
+//CHECK-NEXT: 00 00 00 00 90 90 90 90 - 00 00 00 00 00 00 00 00
load_lib llvm.exp
if { [llvm_supports_target X86] } {
- RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll}]]
+ RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,s}]]
}
--- /dev/null
+// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump --dump-section-data | FileCheck %s
+
+// Test that we get optimal nops in text
+ .text
+f0:
+ .long 0
+ .align 8, 0x90
+ .long 0
+ .align 8
+
+// But not in another section
+ .data
+ .long 0
+ .align 8, 0x90
+ .long 0
+ .align 8
+
+// CHECK: (('sh_name', 1) # '.text'
+// CHECK-NEXT: ('sh_type', 1)
+// CHECK-NEXT: ('sh_flags', 6)
+// CHECK-NEXT: ('sh_addr',
+// CHECK-NEXT: ('sh_offset',
+// CHECK-NEXT: ('sh_size', 16)
+// CHECK-NEXT: ('sh_link', 0)
+// CHECK-NEXT: ('sh_info', 0)
+// CHECK-NEXT: ('sh_addralign', 8)
+// CHECK-NEXT: ('sh_entsize', 0)
+// CHECK-NEXT: ('_section_data', '00000000 0f1f4000 00000000 0f1f4000')
+
+// CHECK: (('sh_name', 7) # '.data'
+// CHECK-NEXT: ('sh_type', 1)
+// CHECK-NEXT: ('sh_flags', 3)
+// CHECK-NEXT: ('sh_addr',
+// CHECK-NEXT: ('sh_offset',
+// CHECK-NEXT: ('sh_size', 16)
+// CHECK-NEXT: ('sh_link', 0)
+// CHECK-NEXT: ('sh_info', 0)
+// CHECK-NEXT: ('sh_addralign', 8)
+// CHECK-NEXT: ('sh_entsize', 0)
+// CHECK-NEXT: ('_section_data', '00000000 90909090 00000000 00000000')