[llvm] r296180 - Disallow redefinition of section symbols.
Evgeniy Stepanov via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 24 13:44:58 PST 2017
Author: eugenis
Date: Fri Feb 24 15:44:58 2017
New Revision: 296180
URL: http://llvm.org/viewvc/llvm-project?rev=296180&view=rev
Log:
Disallow redefinition of section symbols.
Differential Revision: https://reviews.llvm.org/D30235
Added:
llvm/trunk/test/MC/ELF/section-sym-err.s
llvm/trunk/test/MC/ELF/section-sym-err2.s
Removed:
llvm/trunk/test/MC/ELF/section-sym-redefine.s
Modified:
llvm/trunk/lib/MC/MCContext.cpp
llvm/trunk/test/CodeGen/XCore/section-name.ll
llvm/trunk/test/MC/ELF/section.s
Modified: llvm/trunk/lib/MC/MCContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCContext.cpp?rev=296180&r1=296179&r2=296180&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCContext.cpp (original)
+++ llvm/trunk/lib/MC/MCContext.cpp Fri Feb 24 15:44:58 2017
@@ -320,6 +320,11 @@ MCSectionELF *MCContext::createELFSectio
const MCSectionELF *Associated) {
MCSymbolELF *R;
MCSymbol *&Sym = Symbols[Section];
+ // A section symbol can not redefine regular symbols. There may be multiple
+ // sections with the same name, in which case the first such section wins.
+ if (Sym && Sym->isDefined() &&
+ (!Sym->isInSection() || Sym->getSection().getBeginSymbol() != Sym))
+ reportError(SMLoc(), "invalid symbol redefinition");
if (Sym && Sym->isUndefined()) {
R = cast<MCSymbolELF>(Sym);
} else {
@@ -330,7 +335,6 @@ MCSectionELF *MCContext::createELFSectio
}
R->setBinding(ELF::STB_LOCAL);
R->setType(ELF::STT_SECTION);
- R->setRedefinable(true);
auto *Ret = new (ELFAllocator.Allocate()) MCSectionELF(
Section, Type, Flags, K, EntrySize, Group, UniqueID, R, Associated);
Modified: llvm/trunk/test/CodeGen/XCore/section-name.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/XCore/section-name.ll?rev=296180&r1=296179&r2=296180&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/XCore/section-name.ll (original)
+++ llvm/trunk/test/CodeGen/XCore/section-name.ll Fri Feb 24 15:44:58 2017
@@ -1,8 +1,9 @@
-; RUN: llc < %s -march=xcore
+; RUN: not llc < %s -march=xcore 2>&1 | FileCheck %s
-; we used to crash in this.
@bar = internal global i32 zeroinitializer
define void @".dp.bss"() {
ret void
}
+
+; CHECK: LLVM ERROR: invalid symbol redefinition
Added: llvm/trunk/test/MC/ELF/section-sym-err.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/section-sym-err.s?rev=296180&view=auto
==============================================================================
--- llvm/trunk/test/MC/ELF/section-sym-err.s (added)
+++ llvm/trunk/test/MC/ELF/section-sym-err.s Fri Feb 24 15:44:58 2017
@@ -0,0 +1,6 @@
+// RUN: not llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o %t.o 2>&1 | FileCheck %s
+
+.section foo
+foo:
+
+// CHECK: error: invalid symbol redefinition
Added: llvm/trunk/test/MC/ELF/section-sym-err2.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/section-sym-err2.s?rev=296180&view=auto
==============================================================================
--- llvm/trunk/test/MC/ELF/section-sym-err2.s (added)
+++ llvm/trunk/test/MC/ELF/section-sym-err2.s Fri Feb 24 15:44:58 2017
@@ -0,0 +1,6 @@
+// RUN: not llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o %t.o 2>&1 | FileCheck %s
+
+foo:
+.section foo
+
+// CHECK: error: invalid symbol redefinition
Removed: llvm/trunk/test/MC/ELF/section-sym-redefine.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/section-sym-redefine.s?rev=296179&view=auto
==============================================================================
--- llvm/trunk/test/MC/ELF/section-sym-redefine.s (original)
+++ llvm/trunk/test/MC/ELF/section-sym-redefine.s (removed)
@@ -1,138 +0,0 @@
-// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | llvm-readobj -t -r --expand-relocs | FileCheck %s
-
-// Local symbol overriding section.
-.section x1,"a", at progbits
-.local x1
-.comm x1,4,4
-.long x1 // reloc: .bss + 0
-
-// Section declared after local. Local symbol wins.
-.local x2
-.comm x2,4,4
-.section x2,"a", at progbits
-.long x2 // reloc: .bss + 4
-
-// No overriding symbol.
-.section x3,"a", at progbits
-.long x3 // reloc: x3(section) + 0
-
-// Global vs section.
-.section x4,"a", at progbits
-.long 0
-.globl x4
-.section foo, "a", @progbits
-x4:
-.long 0
-.long x4 // reloc: x4(global) + 0
-
-// Global vs implicit section
-.globl .data
-.data:
-.long 42
-.long .data // reloc: .data(global) + 0
-
-// CHECK: Relocations [
-// CHECK: Section (4) .relax1 {
-// CHECK: Relocation {
-// CHECK: Offset: 0x0
-// CHECK: Type: R_X86_64_32 (10)
-// CHECK: Symbol: .bss (3)
-// CHECK: Addend: 0x0
-// CHECK: }
-// CHECK: }
-// CHECK: Section (7) .relax2 {
-// CHECK: Relocation {
-// CHECK: Offset: 0x0
-// CHECK: Type: R_X86_64_32 (10)
-// CHECK: Symbol: .bss (3)
-// CHECK: Addend: 0x4
-// CHECK: }
-// CHECK: }
-// CHECK: Section (9) .relax3 {
-// CHECK: Relocation {
-// CHECK: Offset: 0x0
-// CHECK: Type: R_X86_64_32 (10)
-// CHECK: Symbol: x3 (4)
-// CHECK: Addend: 0x0
-// CHECK: }
-// CHECK: }
-// CHECK: Section (12) .relafoo {
-// CHECK: Relocation {
-// CHECK: Offset: 0x4
-// CHECK: Type: R_X86_64_32 (10)
-// CHECK: Symbol: x4 (6)
-// CHECK: Addend: 0x0
-// CHECK: }
-// CHECK: Relocation {
-// CHECK: Offset: 0xC
-// CHECK: Type: R_X86_64_32 (10)
-// CHECK: Symbol: .data (5)
-// CHECK: Addend: 0x0
-// CHECK: }
-// CHECK: }
-// CHECK: ]
-// CHECK: Symbols [
-// CHECK: Symbol {
-// CHECK: Name: (0)
-// CHECK: Value: 0x0
-// CHECK: Size: 0
-// CHECK: Binding: Local (0x0)
-// CHECK: Type: None (0x0)
-// CHECK: Other: 0
-// CHECK: Section: Undefined (0x0)
-// CHECK: }
-// CHECK: Symbol {
-// CHECK: Name: x1 (67)
-// CHECK: Value: 0x0
-// CHECK: Size: 4
-// CHECK: Binding: Local (0x0)
-// CHECK: Type: Object (0x1)
-// CHECK: Other: 0
-// CHECK: Section: .bss (0x5)
-// CHECK: }
-// CHECK: Symbol {
-// CHECK: Name: x2 (59)
-// CHECK: Value: 0x4
-// CHECK: Size: 4
-// CHECK: Binding: Local (0x0)
-// CHECK: Type: Object (0x1)
-// CHECK: Other: 0
-// CHECK: Section: .bss (0x5)
-// CHECK: }
-// CHECK: Symbol {
-// CHECK: Name: (0)
-// CHECK: Value: 0x0
-// CHECK: Size: 0
-// CHECK: Binding: Local (0x0)
-// CHECK: Type: Section (0x3)
-// CHECK: Other: 0
-// CHECK: Section: .bss (0x5)
-// CHECK: }
-// CHECK: Symbol {
-// CHECK: Name: (0)
-// CHECK: Value: 0x0
-// CHECK: Size: 0
-// CHECK: Binding: Local (0x0)
-// CHECK: Type: Section (0x3)
-// CHECK: Other: 0
-// CHECK: Section: x3 (0x8)
-// CHECK: }
-// CHECK: Symbol {
-// CHECK: Name: .data (37)
-// CHECK: Value: 0x8
-// CHECK: Size: 0
-// CHECK: Binding: Global (0x1)
-// CHECK: Type: None (0x0)
-// CHECK: Other: 0
-// CHECK: Section: foo (0xB)
-// CHECK: }
-// CHECK: Symbol {
-// CHECK: Name: x4 (43)
-// CHECK: Value: 0x0
-// CHECK: Size: 0
-// CHECK: Binding: Global (0x1)
-// CHECK: Type: None (0x0)
-// CHECK: Other: 0
-// CHECK: Section: foo (0xB)
-// CHECK: }
-// CHECK: ]
Modified: llvm/trunk/test/MC/ELF/section.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/section.s?rev=296180&r1=296179&r2=296180&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/section.s (original)
+++ llvm/trunk/test/MC/ELF/section.s Fri Feb 24 15:44:58 2017
@@ -143,12 +143,13 @@ bar:
// Test that we handle the strings like gas
.section bar-"foo"
-.section "foo"
+.section "fooo"
+
// CHECK: Section {
// CHECK: Name: bar-"foo"
// CHECK: Section {
-// CHECK: Name: foo
+// CHECK: Name: fooo
// Test SHF_LINK_ORDER
More information about the llvm-commits
mailing list