30 changes: 5 additions & 25 deletions llvm/lib/Target/TargetLoweringObjectFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,13 @@ SectionKind TargetLoweringObjectFile::getKindForGlobal(const GlobalValue *GV,
// If the initializer for the global contains something that requires a
// relocation, then we may have to drop this into a writable data section
// even though it is marked const.
switch (C->getRelocationInfo()) {
case Constant::NoRelocation:
if (!C->needsRelocation()) {
// If the global is required to have a unique address, it can't be put
// into a mergable section: just drop it into the general read-only
// section instead.
if (!GVar->hasUnnamedAddr())
return SectionKind::getReadOnly();

// If initializer is a null-terminated string, put it in a "cstring"
// section of the right width.
if (ArrayType *ATy = dyn_cast<ArrayType>(C->getType())) {
Expand Down Expand Up @@ -207,20 +206,7 @@ SectionKind TargetLoweringObjectFile::getKindForGlobal(const GlobalValue *GV,
return SectionKind::getReadOnly();
}

case Constant::LocalRelocation:
// In static relocation model, the linker will resolve all addresses, so
// the relocation entries will actually be constants by the time the app
// starts up. However, we can't put this into a mergable section, because
// the linker doesn't take relocations into consideration when it tries to
// merge entries in the section.
if (ReloModel == Reloc::Static)
return SectionKind::getReadOnly();

// Otherwise, the dynamic linker needs to fix it up, put it in the
// writable data.rel.local section.
return SectionKind::getReadOnlyWithRelLocal();

case Constant::GlobalRelocations:
} else {
// In static relocation model, the linker will resolve all addresses, so
// the relocation entries will actually be constants by the time the app
// starts up. However, we can't put this into a mergable section, because
Expand All @@ -243,15 +229,9 @@ SectionKind TargetLoweringObjectFile::getKindForGlobal(const GlobalValue *GV,
if (ReloModel == Reloc::Static)
return SectionKind::getDataNoRel();

switch (C->getRelocationInfo()) {
case Constant::NoRelocation:
return SectionKind::getDataNoRel();
case Constant::LocalRelocation:
return SectionKind::getDataRelLocal();
case Constant::GlobalRelocations:
if (C->needsRelocation())
return SectionKind::getDataRel();
}
llvm_unreachable("Invalid relocation");
return SectionKind::getDataNoRel();
}

/// This method computes the appropriate section to emit the specified global
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/AArch64/emutls_generic.ll
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ entry:
; ARM_64: .section .rodata,
; ARM_64-LABEL: __emutls_t.external_y:
; ARM_64-NEXT: .byte 7
; ARM_64: .section .data.rel.local
; ARM_64: .section .data.rel
; ARM_64: .align 3
; ARM_64-LABEL: __emutls_v.internal_y:
; ARM_64-NEXT: .xword 8
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/ARM/emutls_generic.ll
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ entry:
; ARM_32: .long __emutls_v.internal_y
; ARM_32-NOT: __emutls_t.external_x
; ARM_32-NOT: __emutls_v.external_x:
; ARM_32: .section .data.rel.local
; ARM_32: .section .data.rel
; ARM_32: .align 2
; ARM_32-LABEL: __emutls_v.external_y:
; ARM_32-NEXT: .long 1
Expand All @@ -49,7 +49,7 @@ entry:
; ARM_32: .section .rodata,
; ARM_32-LABEL: __emutls_t.external_y:
; ARM_32-NEXT: .byte 7
; ARM_32: .section .data.rel.local
; ARM_32: .section .data.rel
; ARM_32: .align 2
; ARM_32-LABEL: __emutls_v.internal_y:
; ARM_32-NEXT: .long 8
Expand Down
6 changes: 3 additions & 3 deletions llvm/test/CodeGen/Mips/emutls_generic.ll
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ entry:
; MIPS_32: lw {{.+}}call16(__emutls_get_address
; MIPS_32-NOT: __emutls_t.external_x
; MIPS_32-NOT: __emutls_v.external_x:
; MIPS_32: .section .data.rel.local
; MIPS_32: .section .data.rel
; MIPS_32: .align 2
; MIPS_32-LABEL: __emutls_v.external_y:
; MIPS_32: .section .rodata,
; MIPS_32-LABEL: __emutls_t.external_y:
; MIPS_32-NEXT: .byte 7
; MIPS_32: .section .data.rel.local
; MIPS_32: .section .data.rel
; MIPS_32: .align 2
; MIPS_32-LABEL: __emutls_v.internal_y:
; MIPS_32-NEXT: .4byte 8
Expand All @@ -58,7 +58,7 @@ entry:
; MIPS_64: .section .rodata,
; MIPS_64-LABEL: __emutls_t.external_y:
; MIPS_64-NEXT: .byte 7
; MIPS_64: .section .data.rel.local
; MIPS_64: .section .data.rel
; MIPS_64: .align 3
; MIPS_64-LABEL: __emutls_v.internal_y:
; MIPS_64-NEXT: .8byte 8
Expand Down
8 changes: 4 additions & 4 deletions llvm/test/CodeGen/X86/emutls-pic.ll
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ entry:

;;;;; 32-bit targets

; X32: .section .data.rel.local,
; X32: .section .data.rel,
; X32-LABEL: __emutls_v.i:
; X32-NEXT: .long 4
; X32-NEXT: .long 4
Expand All @@ -114,7 +114,7 @@ entry:
; X32-LABEL: __emutls_t.i:
; X32-NEXT: .long 15

; X32: .section .data.rel.local,
; X32: .section .data.rel,
; X32-LABEL: __emutls_v.j:
; X32-NEXT: .long 4
; X32-NEXT: .long 4
Expand All @@ -136,7 +136,7 @@ entry:

;;;;; 64-bit targets

; X64: .section .data.rel.local,
; X64: .section .data.rel,
; X64-LABEL: __emutls_v.i:
; X64-NEXT: .quad 4
; X64-NEXT: .quad 4
Expand All @@ -147,7 +147,7 @@ entry:
; X64-LABEL: __emutls_t.i:
; X64-NEXT: .long 15

; X64: .section .data.rel.local,
; X64: .section .data.rel,
; X64-LABEL: __emutls_v.j:
; X64-NEXT: .quad 4
; X64-NEXT: .quad 4
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/X86/emutls-pie.ll
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ entry:

;;;;; 32-bit targets

; X32: .section .data.rel.local,
; X32: .section .data.rel,
; X32-LABEL: __emutls_v.i:
; X32-NEXT: .long 4
; X32-NEXT: .long 4
Expand All @@ -116,7 +116,7 @@ entry:

;;;;; 64-bit targets

; X64: .section .data.rel.local,
; X64: .section .data.rel,
; X64-LABEL: __emutls_v.i:
; X64-NEXT: .quad 4
; X64-NEXT: .quad 4
Expand Down
6 changes: 3 additions & 3 deletions llvm/test/CodeGen/X86/emutls_generic.ll
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ entry:
; X86_32: calll __emutls_get_address
; X86_32-NOT: __emutls_t.external_x
; X86_32-NOT: __emutls_v.external_x:
; X86_32: .section .data.rel.local
; X86_32: .section .data.rel
; X86_32: .align 4
; X86_32-LABEL: __emutls_v.external_y:
; X86_32-NEXT: .long 1
Expand All @@ -65,7 +65,7 @@ entry:
; X86_32: .section .rodata,
; X86_32-LABEL: __emutls_t.external_y:
; X86_32-NEXT: .byte 7
; X86_32: .section .data.rel.local
; X86_32: .section .data.rel
; X86_32: .align 4
; X86_32-LABEL: __emutls_v.internal_y:
; X86_32-NEXT: .long 8
Expand Down Expand Up @@ -95,7 +95,7 @@ entry:
; X86_64: .section .rodata,
; X86_64-LABEL: __emutls_t.external_y:
; X86_64-NEXT: .byte 7
; X86_64: .section .data.rel.local
; X86_64: .section .data.rel
; X86_64: .align 8
; X86_64-LABEL: __emutls_v.internal_y:
; X86_64-NEXT: .quad 8
Expand Down
6 changes: 3 additions & 3 deletions llvm/test/CodeGen/X86/rodata-relocs.ll
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ target triple = "x86_64-unknown-linux-gnu"
; PIC: .section .rodata.cst16,"aM",@progbits,16
; PIC: e:
; PIC: e1:
; PIC: .section .data.rel.ro.local,"aw",@progbits
; PIC: .section .data.rel.ro,"aw",@progbits
; PIC: p:
; PIC: t:
; PIC: .section .data.rel.ro,"aw",@progbits
; PIC-NOT: .section
; PIC: p1:
; PIC: t1:
; PIC: .section .data.rel,"aw",@progbits
; PIC: p2:
; PIC: t2:
; PIC: .section .data.rel.local,"aw",@progbits
; PIC-NOT: .section
; PIC: p3:
; PIC: t3: