llvm-6502/lib/MC
Peter Collingbourne c39f5dd0e2 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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@233995 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-03 01:46:11 +00:00
..
MCDisassembler Replace the MCSubtargetInfo parameter with a Triple when creating 2015-03-31 00:10:04 +00:00
MCParser Remove more superfluous .str() and replace std::string concatenation with Twine. 2015-03-30 15:42:36 +00:00
CMakeLists.txt Use ADDITIONAL_HEADER_DIRS in all LLVM CMake projects. 2015-02-11 03:28:02 +00:00
ConstantPools.cpp [cleanup] Re-sort all the #include lines in LLVM using 2015-01-14 11:23:27 +00:00
ELFObjectWriter.cpp Special case the creation of relocation sections. 2015-03-30 13:39:16 +00:00
LLVMBuild.txt
MachObjectWriter.cpp MC: For variable symbols, maintain MCSymbol::Section as a cache. 2015-04-03 01:46:11 +00:00
Makefile
MCAsmBackend.cpp
MCAsmInfo.cpp [NVPTXAsmPrinter] do not print .align on function headers 2015-03-12 01:50:30 +00:00
MCAsmInfoCOFF.cpp
MCAsmInfoDarwin.cpp Remove MCStreamer include which isn't used here. NFC 2015-03-04 01:24:26 +00:00
MCAsmInfoELF.cpp Compute the ELF SectionKind from the flags. 2015-01-29 17:33:21 +00:00
MCAsmStreamer.cpp [MCInstPrinter] Enable MCInstPrinter to change its behavior based on the 2015-03-27 20:36:02 +00:00
MCAssembler.cpp Fix PR23025. 2015-03-26 21:11:00 +00:00
MCCodeEmitter.cpp
MCCodeGenInfo.cpp
MCContext.cpp [WinEH] Generate .xdata for catch handlers 2015-03-31 22:35:44 +00:00
MCDwarf.cpp Reset the CFA offset at the start of every FDE. 2015-03-24 21:47:31 +00:00
MCELF.cpp Add STB_GNU_UNIQUE to the ELF writer. 2015-01-23 04:44:35 +00:00
MCELFObjectTargetWriter.cpp
MCELFStreamer.cpp Split the object streamer callback in one per file format. 2015-03-19 01:50:16 +00:00
MCExpr.cpp MC: For variable symbols, maintain MCSymbol::Section as a cache. 2015-04-03 01:46:11 +00:00
MCInst.cpp Fixup. 2015-02-05 01:13:47 +00:00
MCInstPrinter.cpp Format: Modernize using variadic templates. 2015-02-15 22:15:41 +00:00
MCInstrAnalysis.cpp
MCLabel.cpp
MCLinkerOptimizationHint.cpp This file should always have included MCAssembler and not MCStreamer. NFC 2015-03-04 01:24:24 +00:00
MCMachObjectTargetWriter.cpp
MCMachOStreamer.cpp Don't declare all text sections at the start of the .s 2015-03-20 20:00:01 +00:00
MCNullStreamer.cpp Remove method that is identical to the base class one. 2014-10-14 17:38:38 +00:00
MCObjectFileInfo.cpp Don't print labels that on ELF are never used. 2015-03-11 04:20:31 +00:00
MCObjectStreamer.cpp Don't declare all text sections at the start of the .s 2015-03-20 20:00:01 +00:00
MCObjectWriter.cpp clang-format bits of code to make another patch readable. 2015-03-25 19:24:39 +00:00
MCRegisterInfo.cpp
MCSection.cpp Refactor how passes get a symbol at the end of a section. 2015-03-23 21:22:04 +00:00
MCSectionCOFF.cpp MC: Emit COFF section flags in the "proper" order 2015-02-07 08:26:40 +00:00
MCSectionELF.cpp Add r228980 back. 2015-02-17 20:48:01 +00:00
MCSectionMachO.cpp Close unique sections when switching away from them. 2015-03-27 15:01:40 +00:00
MCStreamer.cpp Close unique sections when switching away from them. 2015-03-27 15:01:40 +00:00
MCSubtargetInfo.cpp Don't print an error message when looking up the scheduling model if user specified -mcpu=help. 2015-04-02 04:27:50 +00:00
MCSymbol.cpp MC: For variable symbols, maintain MCSymbol::Section as a cache. 2015-04-03 01:46:11 +00:00
MCSymbolizer.cpp
MCTargetOptions.cpp Migrate ABIName to MCTargetOptions so that it can be shared between 2015-01-14 00:50:31 +00:00
MCValue.cpp Try to fix the build in MCValue.cpp 2015-02-05 01:23:14 +00:00
MCWin64EH.cpp
MCWinEH.cpp Remove MCStreamer.h include from MCContext.h and explictly include it where necessary. NFC 2015-03-04 01:24:11 +00:00
StringTableBuilder.cpp
SubtargetFeature.cpp Make llc use getHostCPUFeatures when 'native' is specified for cpu. 2015-03-31 05:52:57 +00:00
WinCOFFObjectWriter.cpp Remove more superfluous .str() and replace std::string concatenation with Twine. 2015-03-30 15:42:36 +00:00
WinCOFFStreamer.cpp Fix uses of reserved identifiers starting with an underscore followed by an uppercase letter 2015-03-16 18:06:57 +00:00
YAML.cpp