Skip to content

Commit

Permalink
[XCOFF] change default program code csect alignment to 32
Browse files Browse the repository at this point in the history
This is the same with commercial XLC on AIX.

Reviewed By: Esme

Differential Revision: https://reviews.llvm.org/D114419
  • Loading branch information
chenzheng1030 committed Jun 29, 2022
1 parent 60a8572 commit 370127b
Show file tree
Hide file tree
Showing 25 changed files with 71 additions and 66 deletions.
17 changes: 11 additions & 6 deletions llvm/include/llvm/MC/MCSectionXCOFF.h
Expand Up @@ -38,6 +38,7 @@ class MCSectionXCOFF final : public MCSection {
Optional<XCOFF::DwarfSectionSubtypeFlags> DwarfSubtypeFlags;
bool MultiSymbolsAllowed;
static constexpr unsigned DefaultAlignVal = 4;
static constexpr unsigned DefaultTextAlignVal = 32;

MCSectionXCOFF(StringRef Name, XCOFF::StorageMappingClass SMC,
XCOFF::SymbolType ST, SectionKind K, MCSymbolXCOFF *QualName,
Expand All @@ -57,9 +58,14 @@ class MCSectionXCOFF final : public MCSection {

QualName->setRepresentedCsect(this);
QualName->setStorageClass(XCOFF::C_HIDEXT);
// A csect is 4 byte aligned by default, except for undefined symbol csects.
if (ST != XCOFF::XTY_ER)
setAlignment(Align(DefaultAlignVal));
if (ST != XCOFF::XTY_ER) {
// For a csect for program code, set the alignment to 32 bytes by default.
// For other csects, set the alignment to 4 bytes by default.
if (SMC == XCOFF::XMC_PR)
setAlignment(Align(DefaultTextAlignVal));
else
setAlignment(Align(DefaultAlignVal));
}
}

MCSectionXCOFF(StringRef Name, SectionKind K, MCSymbolXCOFF *QualName,
Expand All @@ -74,9 +80,8 @@ class MCSectionXCOFF final : public MCSection {
// FIXME: use a more meaningful name for non csect sections.
QualName->setRepresentedCsect(this);

// Set default alignment 4 for all non csect sections for now.
// FIXME: set different alignments according to section types.
setAlignment(Align(DefaultAlignVal));
// Use default text alignment as the alignment for DWARF sections.
setAlignment(Align(DefaultTextAlignVal));
}

void printCsectDirective(raw_ostream &OS) const;
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/PowerPC/aix-alias.ll
Expand Up @@ -56,15 +56,15 @@ entry:
; ASM-NEXT: .csect fun[DS]
; ASM-NEXT: fun_weak: # @fun
; ASM-NEXT: fun_hidden:
; ASM: .csect .text[PR],2
; ASM: .csect .text[PR],5
; ASM-NEXT: .fun:
; ASM-NEXT: .fun_weak:
; ASM-NEXT: .fun_hidden:
; ASM-NEXT: # %bb.0:
; ASM-NEXT: li 3, 0
; ASM-NEXT: blr
; ASM-NEXT: # -- End function
; ASM: .csect .text[PR],2
; ASM: .csect .text[PR],5
; ASM-NEXT: .test:
; ASM-NEXT: # %bb.0: # %entry
; ASM: bl .fun
Expand Down
22 changes: 11 additions & 11 deletions llvm/test/CodeGen/PowerPC/aix-dwarf.ll
Expand Up @@ -62,10 +62,10 @@ entry:
; SEC-NEXT: VirtualAddress: 0x28
; SEC32-NEXT: Size: 0xC
; SEC32-NEXT: RawDataOffset: 0x104
; SEC32-NEXT: RelocationPointer: 0x1D8
; SEC32-NEXT: RelocationPointer: 0x1F4
; SEC64-NEXT: Size: 0x18
; SEC64-NEXT: RawDataOffset: 0x1A8
; SEC64-NEXT: RelocationPointer: 0x2B0
; SEC64-NEXT: RelocationPointer: 0x2C8
; SEC-NEXT: LineNumberPointer: 0x0
; SEC-NEXT: NumberOfRelocations: 2
; SEC-NEXT: NumberOfLineNumbers: 0
Expand All @@ -77,7 +77,7 @@ entry:
; SEC-NEXT: PhysicalAddress: 0x0
; SEC-NEXT: VirtualAddress: 0x0
; SEC-NEXT: Size: 0x36
; SEC32-NEXT: RawDataOffset: 0x110
; SEC32-NEXT: RawDataOffset: 0x11C
; SEC64-NEXT: RawDataOffset: 0x1C0
; SEC-NEXT: RelocationPointer: 0x0
; SEC-NEXT: LineNumberPointer: 0x0
Expand All @@ -91,11 +91,11 @@ entry:
; SEC-NEXT: PhysicalAddress: 0x0
; SEC-NEXT: VirtualAddress: 0x0
; SEC32-NEXT: Size: 0x57
; SEC32-NEXT: RawDataOffset: 0x148
; SEC32-NEXT: RelocationPointer: 0x1EC
; SEC32-NEXT: RawDataOffset: 0x15C
; SEC32-NEXT: RelocationPointer: 0x208
; SEC64-NEXT: Size: 0x6F
; SEC64-NEXT: RawDataOffset: 0x1F8
; SEC64-NEXT: RelocationPointer: 0x2CC
; SEC64-NEXT: RawDataOffset: 0x200
; SEC64-NEXT: RelocationPointer: 0x2E4
; SEC-NEXT: LineNumberPointer: 0x0
; SEC-NEXT: NumberOfRelocations: 4
; SEC-NEXT: NumberOfLineNumbers: 0
Expand All @@ -107,11 +107,11 @@ entry:
; SEC-NEXT: PhysicalAddress: 0x0
; SEC-NEXT: VirtualAddress: 0x0
; SEC32-NEXT: Size: 0x36
; SEC32-NEXT: RawDataOffset: 0x1A0
; SEC32-NEXT: RelocationPointer: 0x214
; SEC32-NEXT: RawDataOffset: 0x1BC
; SEC32-NEXT: RelocationPointer: 0x230
; SEC64-NEXT: Size: 0x46
; SEC64-NEXT: RawDataOffset: 0x268
; SEC64-NEXT: RelocationPointer: 0x304
; SEC64-NEXT: RawDataOffset: 0x280
; SEC64-NEXT: RelocationPointer: 0x31C
; SEC-NEXT: LineNumberPointer: 0x0
; SEC-NEXT: NumberOfRelocations: 1
; SEC-NEXT: NumberOfLineNumbers: 0
Expand Down
Expand Up @@ -89,8 +89,8 @@ entry:
; COMMON-NEXT: .align 2
; COMMON-NEXT: .vbyte 4, 0
; COMMON-NEXT: .vbyte 4, 0
; CHECK-ASM-NEXT: .csect .text[PR],2
; CHECK-FUNC-NEXT: .csect .foov[PR],2
; CHECK-ASM-NEXT: .csect .text[PR],5
; CHECK-FUNC-NEXT: .csect .foov[PR],5
; COMMON-NEXT: # -- End function
; COMMON: .toc
; COMMON: L..C2:
Expand Down
8 changes: 4 additions & 4 deletions llvm/test/CodeGen/PowerPC/aix-emit-tracebacktable.ll
Expand Up @@ -141,7 +141,7 @@ entry:
}

; CHECK-ASM-LABEL: ._Z10add_structifd1SP2SD1Di:{{[[:space:]] *}}# %bb.0:
; CHECK-FUNC-LABEL: csect ._Z10add_structifd1SP2SD1Di[PR],2{{[[:space:]] *}}# %bb.0:
; CHECK-FUNC-LABEL: csect ._Z10add_structifd1SP2SD1Di[PR],5{{[[:space:]] *}}# %bb.0:
; COMMON-NEXT: lwz 4, L..C0(2)
; COMMON-NEXT: stfs 1, -24(1)
; COMMON-NEXT: lfs 0, 0(4)
Expand Down Expand Up @@ -174,7 +174,7 @@ entry:


; CHECK-ASM-LABEL: .main:{{[[:space:]] *}}# %bb.0:
; CHECK-FUNC-LABEL: .csect .main[PR],2{{[[:space:]] *}}# %bb.0
; CHECK-FUNC-LABEL: .csect .main[PR],5{{[[:space:]] *}}# %bb.0
; COMMON-NEXT: mflr 0
; COMMON-NEXT: stw 0, 8(1)
; COMMON: mtlr 0
Expand Down Expand Up @@ -202,7 +202,7 @@ entry:


; CHECK-ASM-LABEL: ._Z7add_bari1SfdP2SD1Di:{{[[:space:]] *}}# %bb.0:
; CHECK-FUNC-LABEL: .csect ._Z7add_bari1SfdP2SD1Di[PR],2{{[[:space:]] *}}# %bb.0:
; CHECK-FUNC-LABEL: .csect ._Z7add_bari1SfdP2SD1Di[PR],5{{[[:space:]] *}}# %bb.0:
; COMMON: .vbyte 4, 0x00000000 # Traceback table begin
; COMMON-NEXT: .byte 0x00 # Version = 0
; COMMON-NEXT: .byte 0x09 # Language = CPlusPlus
Expand All @@ -226,7 +226,7 @@ entry:


; CHECK-ASM-LABEL: .foo:{{[[:space:]] *}}# %bb.0:
; CHECK-FUNC-LABEL: .csect .foo[PR],2{{[[:space:]] *}}# %bb.0:
; CHECK-FUNC-LABEL: .csect .foo[PR],5{{[[:space:]] *}}# %bb.0:
; COMMON: stw 3, -4(1)
; COMMON-NEXT: blr
; COMMON-NEXT:L..foo0:
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/PowerPC/aix-exception.ll
Expand Up @@ -28,7 +28,7 @@ entry:
}

; ASMNFS: ._Z9throwFuncv:
; ASMFS: .csect ._Z9throwFuncv[PR],2
; ASMFS: .csect ._Z9throwFuncv[PR],5
; ASM: bl .__cxa_allocate_exception[PR]
; ASM: nop
; ASM32: lwz 4, L..C0(2)
Expand Down Expand Up @@ -90,7 +90,7 @@ eh.resume: ; preds = %catch.dispatch
}

; ASMNFS: ._Z9catchFuncv:
; ASMFS: .csect ._Z9catchFuncv[PR],2
; ASMFS: .csect ._Z9catchFuncv[PR],5
; ASM: L..func_begin0:
; ASM: # %bb.0: # %entry
; ASM: mflr 0
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/PowerPC/aix-extern-weak.ll
Expand Up @@ -192,7 +192,7 @@ declare extern_weak void @foo_ext_weak(i32*)
; CHECKSYM-NEXT: SectionLen: 80
; CHECKSYM-NEXT: ParameterHashIndex: 0x0
; CHECKSYM-NEXT: TypeChkSectNum: 0x0
; CHECKSYM-NEXT: SymbolAlignmentLog2: 4
; CHECKSYM-NEXT: SymbolAlignmentLog2: 5
; CHECKSYM-NEXT: SymbolType: XTY_SD (0x1)
; CHECKSYM-NEXT: StorageMappingClass: XMC_PR (0x0)
; CHECKSYM32-NEXT: StabInfoIndex: 0x0
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/PowerPC/aix-extern.ll
Expand Up @@ -215,7 +215,7 @@ declare i32 @bar_extern(i32*)
; CHECKSYM-NEXT: SectionLen: 112
; CHECKSYM-NEXT: ParameterHashIndex: 0x0
; CHECKSYM-NEXT: TypeChkSectNum: 0x0
; CHECKSYM-NEXT: SymbolAlignmentLog2: 4
; CHECKSYM-NEXT: SymbolAlignmentLog2: 5
; CHECKSYM-NEXT: SymbolType: XTY_SD (0x1)
; CHECKSYM-NEXT: StorageMappingClass: XMC_PR (0x0)
; CHECKSYM32-NEXT: StabInfoIndex: 0x0
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/PowerPC/aix-func-dsc-gen.ll
Expand Up @@ -34,7 +34,7 @@ entry:
; CHECK-NEXT: SectionLen: 4
; CHECK-NEXT: ParameterHashIndex: 0x0
; CHECK-NEXT: TypeChkSectNum: 0x0
; CHECK-NEXT: SymbolAlignmentLog2: 4
; CHECK-NEXT: SymbolAlignmentLog2: 5
; CHECK-NEXT: SymbolType: XTY_SD (0x1)
; CHECK-NEXT: StorageMappingClass: XMC_PR (0x0)
; CHECK-NEXT: StabInfoIndex: 0x0
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/PowerPC/aix-lower-jump-table.ll
Expand Up @@ -190,7 +190,7 @@
; 64LARGE-ASM: .vbyte 4, L..BB0_4-L..JTI0_0
; 64LARGE-ASM: .vbyte 4, L..BB0_5-L..JTI0_0

; FUNC-ASM: .csect .jump_table[PR],2
; FUNC-ASM: .csect .jump_table[PR],5
; FUNC-ASM: L..BB0_2:
; FUNC-ASM: L..BB0_3:
; FUNC-ASM: L..BB0_4:
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/PowerPC/aix-personality-alias.ll
Expand Up @@ -56,7 +56,7 @@ declare void @_Z3barv()
; SYM64: .vbyte 8, .__gxx_personality_v0
; SYM64: .vbyte 8, TOC[TC0]
; SYM64: .vbyte 8, 0
; SYM: .csect .text[PR],2
; SYM: .csect .text[PR],5
; SYM: .__gxx_personality_v0:
; SYM: .__xlcxx_personality_v1:
; SYM: # %bb.0: # %entry
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/PowerPC/aix-tls-xcoff-reloc-large.ll
Expand Up @@ -251,7 +251,7 @@ entry:
; SYM-NEXT: SectionLen: 132
; SYM-NEXT: ParameterHashIndex: 0x0
; SYM-NEXT: TypeChkSectNum: 0x0
; SYM-NEXT: SymbolAlignmentLog2: 4
; SYM-NEXT: SymbolAlignmentLog2: 5
; SYM-NEXT: SymbolType: XTY_SD (0x1)
; SYM-NEXT: StorageMappingClass: XMC_PR (0x0)
; SYM-NEXT: StabInfoIndex: 0x0
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/PowerPC/aix-tls-xcoff-reloc.ll
Expand Up @@ -212,7 +212,7 @@ entry:
; SYM-NEXT: SectionLen: 104
; SYM-NEXT: ParameterHashIndex: 0x0
; SYM-NEXT: TypeChkSectNum: 0x0
; SYM-NEXT: SymbolAlignmentLog2: 4
; SYM-NEXT: SymbolAlignmentLog2: 5
; SYM-NEXT: SymbolType: XTY_SD (0x1)
; SYM-NEXT: StorageMappingClass: XMC_PR (0x0)
; SYM-NEXT: StabInfoIndex: 0x0
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/PowerPC/aix-tls-xcoff-variables.ll
Expand Up @@ -128,7 +128,7 @@
; SYMS-NEXT: SectionLen: 0
; SYMS-NEXT: ParameterHashIndex: 0x0
; SYMS-NEXT: TypeChkSectNum: 0x0
; SYMS-NEXT: SymbolAlignmentLog2: 2
; SYMS-NEXT: SymbolAlignmentLog2: 5
; SYMS-NEXT: SymbolType: XTY_SD (0x1)
; SYMS-NEXT: StorageMappingClass: XMC_PR (0x0)
; SYMS-NEXT: StabInfoIndex: 0x0
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/PowerPC/aix-weak.ll
Expand Up @@ -122,7 +122,7 @@ entry:
; CHECKSYM-NEXT: SectionLen: 136
; CHECKSYM-NEXT: ParameterHashIndex: 0x0
; CHECKSYM-NEXT: TypeChkSectNum: 0x0
; CHECKSYM-NEXT: SymbolAlignmentLog2: 4
; CHECKSYM-NEXT: SymbolAlignmentLog2: 5
; CHECKSYM-NEXT: SymbolType: XTY_SD (0x1)
; CHECKSYM-NEXT: StorageMappingClass: XMC_PR (0x0)
; CHECKSYM32-NEXT: StabInfoIndex: 0x0
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/PowerPC/aix-xcoff-data.ll
Expand Up @@ -45,7 +45,7 @@

; CHECK-NOT: .toc

; CHECK: .csect .text[PR],2
; CHECK: .csect .text[PR],5
; CHECK-NEXT: .file

; CHECK: .csect .data[RW],5
Expand Down Expand Up @@ -229,7 +229,7 @@
; SYMS-NEXT: SectionLen: 0
; SYMS-NEXT: ParameterHashIndex: 0x0
; SYMS-NEXT: TypeChkSectNum: 0x0
; SYMS-NEXT: SymbolAlignmentLog2: 2
; SYMS-NEXT: SymbolAlignmentLog2: 5
; SYMS-NEXT: SymbolType: XTY_SD (0x1)
; SYMS-NEXT: StorageMappingClass: XMC_PR (0x0)
; SYMS32-NEXT: StabInfoIndex: 0x0
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/PowerPC/aix-xcoff-explicit-section.ll
Expand Up @@ -25,7 +25,7 @@ entry:
; CHECK-NEXT: .globl .ext_fun
; CHECK-NEXT: .align 4
; CHECK-NEXT: .csect ext_fun[DS]
; CHECK: .csect .ext_fun_sec[PR],2
; CHECK: .csect .ext_fun_sec[PR],5
; CHECK-NEXT: .ext_fun:
; CHECK: .csect .ext_const_sec[RO],2
; CHECK-NEXT: .globl ext_const
Expand Down Expand Up @@ -90,7 +90,7 @@ entry:
; CHECKSYM-NEXT: SectionLen: 28
; CHECKSYM-NEXT: ParameterHashIndex: 0x0
; CHECKSYM-NEXT: TypeChkSectNum: 0x0
; CHECKSYM-NEXT: SymbolAlignmentLog2: 4
; CHECKSYM-NEXT: SymbolAlignmentLog2: 5
; CHECKSYM-NEXT: SymbolType: XTY_SD (0x1)
; CHECKSYM-NEXT: StorageMappingClass: XMC_PR (0x0)
; CHECKSYM-NEXT: StabInfoIndex: 0x0
Expand Down
10 changes: 5 additions & 5 deletions llvm/test/CodeGen/PowerPC/aix-xcoff-funcsect.ll
Expand Up @@ -34,7 +34,7 @@ entry:
ret void
}

; ASM: .csect .foo[PR],2
; ASM: .csect .foo[PR],5
; ASM-NEXT: .globl foo[DS] # -- Begin function foo
; ASM-NEXT: .globl .foo[PR]
; ASM-NEXT: .align 4
Expand All @@ -43,11 +43,11 @@ entry:
; ASM-NEXT: .vbyte {{[0-9]+}}, .foo[PR]
; ASM-NEXT: .vbyte {{[0-9]+}}, TOC[TC0]
; ASM-NEXT: .vbyte {{[0-9]+}}, 0
; ASM-NEXT: .csect .foo[PR],2
; ASM-NEXT: .csect .foo[PR],5
; ASM-NEXT: .alias_foo:
; ASM-NEXT: # %bb.0: # %entry
; ASM-NEXT: blr
; ASM: .csect .hidden_foo[PR],2
; ASM: .csect .hidden_foo[PR],5
; ASM-NEXT: .globl hidden_foo[DS],hidden # -- Begin function hidden_foo
; ASM-NEXT: .globl .hidden_foo[PR],hidden
; ASM-NEXT: .align 4
Expand All @@ -58,15 +58,15 @@ entry:
; ASM-NEXT: .csect .hidden_foo[PR]
; ASM-NEXT: # %bb.0: # %entry
; ASM-NEXT: blr
; ASM: .csect .bar[PR],2
; ASM: .csect .bar[PR],5
; ASM-NEXT: .globl bar[DS] # -- Begin function bar
; ASM-NEXT: .globl .bar[PR]
; ASM-NEXT: .align 4
; ASM-NEXT: .csect bar[DS]
; ASM-NEXT: .vbyte {{[0-9]+}}, .bar[PR] # @bar
; ASM-NEXT: .vbyte {{[0-9]+}}, TOC[TC0]
; ASM-NEXT: .vbyte {{[0-9]+}}, 0
; ASM-NEXT: .csect .bar[PR],2
; ASM-NEXT: .csect .bar[PR],5
; ASM-NEXT: # %bb.0: # %entry
; ASM: bl .foo[PR]
; ASM-NEXT: nop
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/PowerPC/aix-xcoff-reloc-symb.mir
Expand Up @@ -47,7 +47,7 @@ body: |
# SYM-NEXT: SectionLen: 8
# SYM-NEXT: ParameterHashIndex: 0x0
# SYM-NEXT: TypeChkSectNum: 0x0
# SYM-NEXT: SymbolAlignmentLog2: 4
# SYM-NEXT: SymbolAlignmentLog2: 5
# SYM-NEXT: SymbolType: XTY_SD (0x1)
# SYM-NEXT: StorageMappingClass: XMC_PR (0x0)
# SYM-NEXT: StabInfoIndex: 0x0
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/PowerPC/aix-xcoff-reloc.ll
Expand Up @@ -222,7 +222,7 @@ declare i32 @bar(i32)
; SYM-NEXT: SectionLen: 64
; SYM-NEXT: ParameterHashIndex: 0x0
; SYM-NEXT: TypeChkSectNum: 0x0
; SYM-NEXT: SymbolAlignmentLog2: 4
; SYM-NEXT: SymbolAlignmentLog2: 5
; SYM-NEXT: SymbolType: XTY_SD (0x1)
; SYM-NEXT: StorageMappingClass: XMC_PR (0x0)
; SYM32-NEXT: StabInfoIndex: 0x0
Expand Down
6 changes: 3 additions & 3 deletions llvm/test/CodeGen/PowerPC/aix-xcoff-symbol-rename.ll
Expand Up @@ -54,7 +54,7 @@ declare i32 @"f\40o"(...)
; ASM-NEXT: .vbyte 4, ._Renamed..24f_o # @"f$o"
; ASM-NEXT: .vbyte 4, TOC[TC0]
; ASM-NEXT: .vbyte 4, 0
; ASM-NEXT: .csect .text[PR],2
; ASM-NEXT: .csect .text[PR],5
; ASM-NEXT: ._Renamed..24f_o:
; ASM: bl ._Renamed..40f_o[PR]
; ASM-NEXT: nop
Expand All @@ -67,7 +67,7 @@ declare i32 @"f\40o"(...)
; ASM-NEXT: .vbyte 4, ._Renamed..26f_o # @"f&o"
; ASM-NEXT: .vbyte 4, TOC[TC0]
; ASM-NEXT: .vbyte 4, 0
; ASM-NEXT: .csect .text[PR],2
; ASM-NEXT: .csect .text[PR],5
; ASM-NEXT: ._Renamed..26f_o:
; ASM: bl ._Renamed..24f_o
; ASM: .globl _Renamed..265ff__o[DS] # -- Begin function f&_o
Expand All @@ -79,7 +79,7 @@ declare i32 @"f\40o"(...)
; ASM-NEXT: .vbyte 4, ._Renamed..265ff__o # @"f&_o"
; ASM-NEXT: .vbyte 4, TOC[TC0]
; ASM-NEXT: .vbyte 4, 0
; ASM-NEXT: .csect .text[PR],2
; ASM-NEXT: .csect .text[PR],5
; ASM-NEXT: ._Renamed..265ff__o:
; ASM: .csect .data[RW],2
; ASM-NEXT: .globl _Renamed..60f_o
Expand Down

0 comments on commit 370127b

Please sign in to comment.