2013-04-12 12:06:46 +08:00
|
|
|
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | llvm-readobj -t | FileCheck %s
|
2010-10-06 02:01:23 +08:00
|
|
|
|
|
|
|
foo:
|
|
|
|
bar = foo
|
|
|
|
|
2010-10-06 06:26:43 +08:00
|
|
|
.globl foo2
|
|
|
|
foo2 = bar2
|
|
|
|
|
|
|
|
foo3:
|
|
|
|
.globl bar3
|
|
|
|
bar3 = foo3
|
|
|
|
|
2014-03-19 08:26:58 +08:00
|
|
|
|
|
|
|
// Test that bar4 and bar 5 are also functions and have the same value as foo4.
|
|
|
|
.byte 0
|
|
|
|
.type foo4,@function
|
2010-10-07 05:02:29 +08:00
|
|
|
foo4:
|
|
|
|
bar4 = foo4
|
2014-03-18 18:36:11 +08:00
|
|
|
bar5 = bar4
|
|
|
|
|
2010-10-30 07:09:31 +08:00
|
|
|
.long foo2
|
2013-04-12 12:06:46 +08:00
|
|
|
|
2014-12-24 18:27:50 +08:00
|
|
|
// Test that bar6 is a function that doesn't have the same value as foo4.
|
|
|
|
bar6 = bar5
|
|
|
|
bar6:
|
|
|
|
|
MC: For variable symbols, maintain MCSymbol::Section as a cache.
Fixes PR19582.
Previously, when an asm assignment (.set or =) was created, we would look up
the section immediately in MCSymbol::setVariableValue. This caused symbols
to receive the wrong section if the RHS of the assignment had not been seen
yet. This had a knock-on effect in the object file emitters, causing them
to emit extra symbols, or to give symbols the wrong visibility or the wrong
section. For example, in the following asm:
.data
.Llocal:
.text
leaq .Llocal1(%rip), %rdi
.Llocal1 = .Llocal2
.Llocal2 = .Llocal
the first assignment would give .Llocal1 a null section, which would never get
fixed up by the second assignment. This would cause the ELF object file emitter
to consider .Llocal1 to be an undefined symbol and give it external linkage,
even though .Llocal1 should not have been emitted at all in the object file.
Or in the following asm:
alias_to_local = Ltmp0
Ltmp0:
the Mach-O object file emitter would give the alias_to_local symbol a n_type
of N_SECT and a n_sect of 0. This is invalid under the Mach-O specification,
which requires N_SECT symbols to receive a non-zero section number if the
symbol is defined in a section in the object file.
https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/MachORuntime/#//apple_ref/c/tag/nlist
After this change we do not look up the section when the assignment is created,
but instead look it up on demand and store it in Section, which is treated
as a cache if the symbol is a variable symbol.
This change also fixes a bug in MCExpr::FindAssociatedSection. Previously,
if we saw a subtraction, we would return the first referenced section, even in
cases where we should have been returning the absolute pseudo-section. Now we
always return the absolute pseudo-section for expressions that subtract two
section-derived expressions. This isn't always correct (e.g. if one of the
sections ends up being laid out at an absolute address), but it's probably
the best we can do without more context.
This allows us to remove code in two places where we appear to have been
working around this bug, in MachObjectWriter::markAbsoluteVariableSymbols
and in X86AsmPrinter::EmitStartOfAsmFile.
Re-applies r233595 (aka D8586), which was reverted in r233898.
Differential Revision: http://reviews.llvm.org/D8798
llvm-svn: 233995
2015-04-03 09:46:11 +08:00
|
|
|
// Test that indirect local aliases do not appear as symbols.
|
|
|
|
.data
|
|
|
|
.Llocal:
|
|
|
|
|
|
|
|
.text
|
|
|
|
leaq .Llocal1(%rip), %rdi
|
|
|
|
.Llocal1 = .Llocal2
|
|
|
|
.Llocal2 = .Llocal
|
|
|
|
|
2013-04-12 12:06:46 +08:00
|
|
|
// CHECK: Symbols [
|
|
|
|
// CHECK-NEXT: Symbol {
|
2013-06-06 04:33:54 +08:00
|
|
|
// CHECK-NEXT: Name: (0)
|
|
|
|
// CHECK-NEXT: Value: 0x0
|
|
|
|
// CHECK-NEXT: Size: 0
|
|
|
|
// CHECK-NEXT: Binding: Local (0x0)
|
|
|
|
// CHECK-NEXT: Type: None (0x0)
|
|
|
|
// CHECK-NEXT: Other: 0
|
2014-03-24 13:00:34 +08:00
|
|
|
// CHECK-NEXT: Section: Undefined (0x0)
|
2013-06-06 04:33:54 +08:00
|
|
|
// CHECK-NEXT: }
|
|
|
|
// CHECK-NEXT: Symbol {
|
2013-04-12 12:06:46 +08:00
|
|
|
// CHECK-NEXT: Name: bar
|
|
|
|
// CHECK-NEXT: Value: 0x0
|
|
|
|
// CHECK-NEXT: Size: 0
|
|
|
|
// CHECK-NEXT: Binding: Local
|
|
|
|
// CHECK-NEXT: Type: None
|
|
|
|
// CHECK-NEXT: Other: 0
|
|
|
|
// CHECK-NEXT: Section: .text
|
|
|
|
// CHECK-NEXT: }
|
|
|
|
// CHECK-NEXT: Symbol {
|
|
|
|
// CHECK-NEXT: Name: bar4
|
2014-03-19 08:26:58 +08:00
|
|
|
// CHECK-NEXT: Value: 0x1
|
2013-04-12 12:06:46 +08:00
|
|
|
// CHECK-NEXT: Size: 0
|
|
|
|
// CHECK-NEXT: Binding: Local
|
|
|
|
// CHECK-NEXT: Type: Function
|
|
|
|
// CHECK-NEXT: Other: 0
|
|
|
|
// CHECK-NEXT: Section: .text
|
|
|
|
// CHECK-NEXT: }
|
|
|
|
// CHECK-NEXT: Symbol {
|
2014-03-18 18:36:11 +08:00
|
|
|
// CHECK-NEXT: Name: bar5
|
2014-03-19 08:26:58 +08:00
|
|
|
// CHECK-NEXT: Value: 0x1
|
2014-03-18 18:36:11 +08:00
|
|
|
// CHECK-NEXT: Size: 0
|
|
|
|
// CHECK-NEXT: Binding: Local
|
|
|
|
// CHECK-NEXT: Type: Function
|
|
|
|
// CHECK-NEXT: Other: 0
|
|
|
|
// CHECK-NEXT: Section: .text
|
|
|
|
// CHECK-NEXT: }
|
|
|
|
// CHECK-NEXT: Symbol {
|
2014-12-24 18:27:50 +08:00
|
|
|
// CHECK-NEXT: Name: bar6
|
|
|
|
// CHECK-NEXT: Value: 0x5
|
|
|
|
// CHECK-NEXT: Size: 0
|
|
|
|
// CHECK-NEXT: Binding: Local
|
|
|
|
// CHECK-NEXT: Type: None
|
|
|
|
// CHECK-NEXT: Other: 0
|
|
|
|
// CHECK-NEXT: Section: .text
|
|
|
|
// CHECK-NEXT: }
|
|
|
|
// CHECK-NEXT: Symbol {
|
2013-04-12 12:06:46 +08:00
|
|
|
// CHECK-NEXT: Name: foo
|
|
|
|
// CHECK-NEXT: Value: 0x0
|
|
|
|
// CHECK-NEXT: Size: 0
|
|
|
|
// CHECK-NEXT: Binding: Local
|
|
|
|
// CHECK-NEXT: Type: None
|
|
|
|
// CHECK-NEXT: Other: 0
|
|
|
|
// CHECK-NEXT: Section: .text
|
|
|
|
// CHECK-NEXT: }
|
|
|
|
// CHECK-NEXT: Symbol {
|
|
|
|
// CHECK-NEXT: Name: foo3
|
|
|
|
// CHECK-NEXT: Value: 0x0
|
|
|
|
// CHECK-NEXT: Size: 0
|
|
|
|
// CHECK-NEXT: Binding: Local
|
|
|
|
// CHECK-NEXT: Type: None
|
|
|
|
// CHECK-NEXT: Other: 0
|
|
|
|
// CHECK-NEXT: Section: .text
|
|
|
|
// CHECK-NEXT: }
|
|
|
|
// CHECK-NEXT: Symbol {
|
|
|
|
// CHECK-NEXT: Name: foo4
|
2014-03-19 08:26:58 +08:00
|
|
|
// CHECK-NEXT: Value: 0x1
|
2013-04-12 12:06:46 +08:00
|
|
|
// CHECK-NEXT: Size: 0
|
|
|
|
// CHECK-NEXT: Binding: Local
|
|
|
|
// CHECK-NEXT: Type: Function
|
|
|
|
// CHECK-NEXT: Other: 0
|
|
|
|
// CHECK-NEXT: Section: .text
|
|
|
|
// CHECK-NEXT: }
|
|
|
|
// CHECK-NEXT: Symbol {
|
2015-06-03 13:14:22 +08:00
|
|
|
// CHECK-NEXT: Name: (0)
|
2015-03-25 05:47:00 +08:00
|
|
|
// CHECK-NOT: Symbol {
|
2013-04-12 12:06:46 +08:00
|
|
|
// CHECK: }
|
|
|
|
// CHECK-NEXT: Symbol {
|
2015-05-29 05:59:34 +08:00
|
|
|
// CHECK-NEXT: Name: bar2
|
2013-04-12 12:06:46 +08:00
|
|
|
// CHECK-NEXT: Value: 0x0
|
|
|
|
// CHECK-NEXT: Size: 0
|
|
|
|
// CHECK-NEXT: Binding: Global
|
|
|
|
// CHECK-NEXT: Type: None
|
|
|
|
// CHECK-NEXT: Other: 0
|
2015-05-29 05:59:34 +08:00
|
|
|
// CHECK-NEXT: Section: Undefined (0x0)
|
2013-04-12 12:06:46 +08:00
|
|
|
// CHECK-NEXT: }
|
|
|
|
// CHECK-NEXT: Symbol {
|
2015-05-29 05:59:34 +08:00
|
|
|
// CHECK-NEXT: Name: bar3
|
2013-04-12 12:06:46 +08:00
|
|
|
// CHECK-NEXT: Value: 0x0
|
|
|
|
// CHECK-NEXT: Size: 0
|
|
|
|
// CHECK-NEXT: Binding: Global
|
|
|
|
// CHECK-NEXT: Type: None
|
|
|
|
// CHECK-NEXT: Other: 0
|
2015-05-29 05:59:34 +08:00
|
|
|
// CHECK-NEXT: Section: .text
|
2013-04-12 12:06:46 +08:00
|
|
|
// CHECK-NEXT: }
|
|
|
|
// CHECK-NEXT: ]
|