aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MCExpr.cpp
AgeCommit message (Collapse)AuthorFilesLines
2016-08-22[MC] Remove guard(s). NFCI.Davide Italiano1-2/+0
All the methods are already marked with LLVM_DUMP_METHOD. llvm-svn: 279428
2016-05-20[MCExpr] avoid UB via negation of INT_MINSanjay Patel1-2/+5
I accidentally exposed a bug in MCExpr::evaluateAsRelocatableImpl() with the test file added in: http://reviews.llvm.org/rL269977 Differential Revision: http://reviews.llvm.org/D20434 llvm-svn: 270218
2016-05-03[mips] Use MipsMCExpr instead of MCSymbolRefExpr for all relocations.Daniel Sanders1-28/+3
Summary: This is much closer to the way MIPS relocation expressions work (%hi(foo + 2) rather than %hi(foo) + 2) and removes the need for the various bodges in MipsAsmParser::evaluateRelocExpr(). Removing those bodges ensures that the constant stored in MCValue is the full 32 or 64-bit (depending on ABI) offset from the symbol. This will be used to correct the %hi/%lo matching needed to sort the relocation table correctly. As part of this: * Gave MCExpr::print() the ability to omit parenthesis when emitting a symbol reference inside a MipsMCExpr operator like %hi(X). Without this we print things like %lo(($L1)). * %hi(%neg(%gprel(X))) is now three MipsMCExpr's instead of one. Most of the related special cases have been removed or moved to MipsMCExpr. We can remove the rest as we gain support for the less common relocations when they are not part of this specific combination. * Renamed MipsMCExpr::VariantKind and the enum prefix ('VK_') to avoid confusion with MCSymbolRefExpr::VariantKind and its prefix (also 'VK_'). * fixup_Mips_GOT_Local and fixup_Mips_GOT_Global were found to be identical and merged into fixup_Mips_GOT. * MO_GOT16 and MO_GOT turned out to be identical and have been merged into MO_GOT. * VK_Mips_GOT and VK_Mips_GOT16 turned out to be the same thing so they have been merged into MEK_GOT Reviewers: sdardis Subscribers: dsanders, sdardis, llvm-commits Differential Revision: http://reviews.llvm.org/D19716 llvm-svn: 268379
2016-03-15[MC] Rename TLSDESC as it's not ARM specific.Davide Italiano1-2/+2
Similarly to what was done for TLSCALL in r263515. llvm-svn: 263564
2016-03-15[MC] Rename TLSCALL as it's not ARM specific.Davide Italiano1-2/+2
`MCSymbolRefExpr` variant kind for TLSCALL is prefixed with _ARM_ since this is how it was originally implemented. The X86_64 version is exactly the same so there's no reason to create a new variant, we can just rename the existing one to be machine-independent. This generalization is the first step to implement support for GNU2 TLS dialect in MC. Differential Revision: http://reviews.llvm.org/D18160 llvm-svn: 263515
2016-02-10[MC] Merge VK_PPC_TPREL in to generic VK_TPREL.Colin LeMahieu1-8/+6
Differential Revision: http://reviews.llvm.org/D17038 llvm-svn: 260401
2016-02-09[MC] Adding GOTREL expression variant.Colin LeMahieu1-0/+2
llvm-svn: 260258
2016-01-29Annotate dump() methods with LLVM_DUMP_METHOD, addressing Richard Smith ↵Yaron Keren1-1/+1
r259192 post commit comment. clang part in r259232, this is the LLVM part of the patch. llvm-svn: 259240
2016-01-11[WebAssembly] Define WebAssembly-specific relocation codes.Dan Gohman1-0/+1
Currently WebAssembly has two kinds of relocations; data addresses and function addresses. This adds ELF relocations for them, as well as an MC symbol kind to indicate which type of relocation is needed. llvm-svn: 257416
2015-12-18Recognize strings for Hexagon-specific variant kindsKrzysztof Parzyszek1-0/+7
llvm-svn: 256007
2015-11-02ELF can handle some relocations of the form -sym + constant.Rafael Espindola1-5/+0
Remove code that was assuming that this would never work. Thanks to Colin LeMahie for finding and diagnosing the bug. llvm-svn: 251818
2015-10-26ARM/ELF: Better codegen for global variable addresses.Peter Collingbourne1-1/+2
In PIC mode we were previously computing global variable addresses (or GOT entry addresses) by adding the PC, the PC-relative GOT displacement and the GOT-relative symbol/GOT entry displacement. Because the latter two displacements are fixed, we ended up performing one more addition than necessary. This change causes us to compute addresses using a single PC-relative displacement, resulting in a shorter code sequence. This reduces code size by about 4% in a recent build of Chromium for Android. As a result of this change we no longer need to compute the GOT base address in the ARM backend, which allows us to remove the Global Base Reg pass and SDAG lowering for the GOT. We also now no longer use the GOT when addressing a symbol which is known to be defined in the same linkage unit. Specifically, the symbol must have either hidden visibility or a strong definition in the current module in order to not use the the GOT. This is a change from the previous behaviour where we would use the GOT to address externally visible symbols defined in the same module. I think the only cases where this could matter are cases involving symbol interposition, but we don't really support that well anyway. Differential Revision: http://reviews.llvm.org/D13650 llvm-svn: 251322
2015-10-15Prevent assertion with "llc -debug" and anonymous symbols.Tim Northover1-1/+1
llvm-svn: 250425
2015-10-05Fix pr24486.Rafael Espindola1-25/+20
This extends the work done in r233995 so that now getFragment (in addition to getSection) also works for variable symbols. With that the existing logic to decide if a-b can be computed works even if a or b are variables. Given that, the expression evaluation can avoid expanding variables as aggressively and that in turn lets the relocation code see the original variable. In order for this to work with the asm streamer, there is now a dummy fragment per section. It is used to assign a section to a symbol when no other fragment exists. This patch is a joint work by Maxim Ostapenko andy myself. llvm-svn: 249303
2015-09-11[MC] Fix style bugs introduced in r247471. Reported by Rafael Espindola.Davide Italiano1-3/+3
llvm-svn: 247483
2015-09-11[MC] Don't crash on division by zero.Davide Italiano1-1/+11
Differential Revision: http://reviews.llvm.org/D12776 llvm-svn: 247471
2015-06-23MCExpr: Avoid UB by evaluating this shift as unsignedJustin Bogner1-1/+1
We hit undefined behaviour in some MCExpr tests when the LHS of a left shift is -1. Twos-complement semantics are completely reasonable here, so we should just do the shift in unsigned. llvm-svn: 240385
2015-06-09MC: Add target hook to control symbol quotingMatt Arsenault1-12/+18
llvm-svn: 239370
2015-06-04MC: Clean up naming in MCObjectWriter. NFC.Jim Grosbach1-1/+1
s/WriteObject/writeObject/ s/RecordRelocation/recordRelocation/ s/IsSymbolRefDifferenceFullyResolved/isSymbolRefDifferenceFullyResolved/ s/Write8/write8/ s/WriteLE16/writeLE16/ s/WriteLE32/writeLE32/ s/WriteLE64/writeLE64/ s/WriteBE16/writeBE16/ s/WriteBE32/writeBE32/ s/WriteBE64/writeBE64/ s/Write16/write16/ s/Write32/write32/ s/Write64/write64/ s/WriteZeroes/writeZeroes/ s/WriteBytes/writeBytes/ llvm-svn: 239108
2015-06-03Remember if a weakref of a symbol has been used.Rafael Espindola1-0/+7
This avoids yet another last minute patching of the binding. While at it, also simplify the weakref implementation a bit by not walking past it in the expression evaluation. llvm-svn: 238982
2015-05-30MC: Clean up MCExpr naming. NFC.Jim Grosbach1-31/+31
llvm-svn: 238634
2015-05-29Remove getData.Rafael Espindola1-6/+3
This completes the mechanical part of merging MCSymbol and MCSymbolData. llvm-svn: 238617
2015-05-29Remove the MCSymbolData typedef.Rafael Espindola1-2/+2
The getData member function is next. llvm-svn: 238611
2015-05-29Move common symbol related information from MCSectionData to MCSymbol.Rafael Espindola1-1/+1
llvm-svn: 238583
2015-05-29Fix crash in MCExpr::print.Pete Cooper1-1/+1
Symbols are no longer required to be named, but this leads to a crash here if an unnamed symbol checks that its first character is '$'. Change the code to first check for a name, then check its first character. No test case i'm afraid as this is debugging code, but any test case with temp labels and 'llc --debug --filetype=obj' would have crashed. llvm-svn: 238579
2015-05-28Remove a trivial forwarding function. NFC.Rafael Espindola1-2/+2
llvm-svn: 238506
2015-05-27Use operator<< instead of print in a few more places.Rafael Espindola1-1/+1
llvm-svn: 238315
2015-05-26Stop using MCSectionData in MCExpr.h.Rafael Espindola1-2/+1
llvm-svn: 238163
2015-05-26Return a MCSection from MCFragment::getParent().Rafael Espindola1-3/+4
Another step in merging MCSectionData and MCSection. llvm-svn: 238162
2015-05-21Move alignment from MCSectionData to MCSection.Rafael Espindola1-3/+3
This starts merging MCSection and MCSectionData. There are a few issues with the current split between MCSection and MCSectionData. * It optimizes the the not as important case. We want the production of .o files to be really fast, but the split puts the information used for .o emission in a separate data structure. * The ELF/COFF/MachO hierarchy is not represented in MCSectionData, leading to some ad-hoc ways to represent the various flags. * It makes it harder to remember where each item is. The attached patch starts merging the two by moving the alignment from MCSectionData to MCSection. Most of the patch is actually just dropping 'const', since MCSectionData is mutable, but MCSection was not. llvm-svn: 237936
2015-05-20MC: Use MCSymbol in MCObjectWriter::isWeak(), NFCDuncan P. N. Exon Smith1-2/+1
Continue to prefer `MCSymbol` when we need both. llvm-svn: 237798
2015-05-19MC: Use MCSymbol in MCAsmLayout::getSymbolOffset(), NFCDuncan P. N. Exon Smith1-2/+2
Continue to canonicalize on MCSymbol instead of MCSymbolData when both are needed. llvm-svn: 237749
2015-05-18MC: Clean up method names in MCContext.Jim Grosbach1-1/+1
The naming was a mish-mash of old and new style. Update to be consistent with the new. NFC. llvm-svn: 237594
2015-05-01[Hexagon] Adding expression MC emission and removing XFAIL from test that ↵Colin LeMahieu1-0/+12
hits this code path. llvm-svn: 236348
2015-04-28[MC] Split MCBinaryExpr::Shr into LShr and AShr.Ahmed Bougacha1-4/+6
Defaulting to AShr without consulting the target MCAsmInfo isn't OK. Add a flag to fix that. Keep it off for now: target migrations will follow in separate commits. llvm-svn: 235951
2015-04-03MC: For variable symbols, maintain MCSymbol::Section as a cache.Peter Collingbourne1-0/+4
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-02Revert r233595, "MC: For variable symbols, maintain MCSymbol::Section as a ↵Peter Collingbourne1-3/+0
cache." llvm-svn: 233898
2015-03-30MC: For variable symbols, maintain MCSymbol::Section as a cache.Peter Collingbourne1-0/+3
This fixes the visibility of symbols in certain edge cases involving aliases with multiple levels of indirection. Fixes PR19582. Differential Revision: http://reviews.llvm.org/D8586 llvm-svn: 233595
2015-03-26Fix PR23025.Rafael Espindola1-4/+13
There is something in link.exe that requires a relocation to use a global symbol. Not doing so breaks the chrome build on windows. This patch sets isWeak for that to work. To compensate, we then need to look past those symbols when not creating relocations. This patch includes an ELF test that matches GNU as behaviour. I am still reducing the chrome build issue and will add a test once that is done. llvm-svn: 233318
2015-03-25clang-format bits of code to make another patch readable.Rafael Espindola1-18/+11
llvm-svn: 233203
2015-03-25Fix fixup evaluation when deciding what to relocate with.Rafael Espindola1-38/+30
The previous logic was to first try without relocations at all and failing that stop on the first defined symbol. That was inefficient and incorrect in the case part of the expression could be simplified and another part could not (see included test). We now stop the evaluation when we get to a variable whose value can change (i.e. is weak). llvm-svn: 233187
2015-03-25Produce an error instead of asserting on invalid .sleb128/.uleb128.Rafael Espindola1-7/+4
llvm-svn: 233155
2015-03-04Expand variables when evaluating absolute expressions.Rafael Espindola1-1/+1
This allows for variables to be used in .size. This matches gnu AS functionality. llvm-svn: 231295
2015-03-04[MC][Target] Implement support for R_X86_64_SIZE{32,64}.Davide Italiano1-0/+2
Differential Revision: D7990 Reviewed by: rafael, majnemer llvm-svn: 231216
2015-01-11ARM: add support for segment base relocations (SBREL)Saleem Abdulrasool1-0/+2
This adds support for parsing and emitting the SBREL relocation variant for the ARM target. Handling this relocation variant is necessary for supporting the full ARM ELF specification. Addresses PR22128. llvm-svn: 225595
2014-12-18Instead of explicitely comparing both lowercase and uppercase variants.Roman Divacky1-81/+1
.lower() the Name and compare only the lowecase. Removing 81 compares/lines of code. This changes the accepted string to be mixed lower/upper case but it should be ok. Discussed with Jim Grosbach. llvm-svn: 224547
2014-12-18Add a corresponding '@LOCAL' parse to match r224415.Justin Hibbits1-0/+1
Pointed out by Jim Grosbach. llvm-svn: 224494
2014-12-17Add parsing of 'foo@local".Justin Hibbits1-0/+1
Summary: Currently, it supports generating, but not parsing, this expression. Test added as well. Test Plan: New test added, no regressions due to this. Reviewers: hfinkel Reviewed By: hfinkel Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D6672 llvm-svn: 224415
2014-11-12Add support for small-model PIC for PowerPC.Justin Hibbits1-0/+1
Summary: Large-model was added first. With the addition of support for multiple PIC models in LLVM, now add small-model PIC for 32-bit PowerPC, SysV4 ABI. This generates more optimal code, for shared libraries with less than about 16380 data objects. Test Plan: Test cases added or updated Reviewers: joerg, hfinkel Reviewed By: hfinkel Subscribers: jholewinski, mcrosier, emaste, llvm-commits Differential Revision: http://reviews.llvm.org/D5399 llvm-svn: 221791
2014-10-11MC: Shrink MCSymbolRefExpr by only storing the bits we need.Benjamin Kramer1-8/+19
32 -> 16 bytes on x86_64. NFC. llvm-svn: 219574