summaryrefslogtreecommitdiffstats
path: root/llvm/lib/MC/MCExpr.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* [WebAssembly] Define WebAssembly-specific relocation codes.Dan Gohman2016-01-111-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
* Recognize strings for Hexagon-specific variant kindsKrzysztof Parzyszek2015-12-181-0/+7
| | | | llvm-svn: 256007
* ELF can handle some relocations of the form -sym + constant.Rafael Espindola2015-11-021-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
* ARM/ELF: Better codegen for global variable addresses.Peter Collingbourne2015-10-261-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
* Prevent assertion with "llc -debug" and anonymous symbols.Tim Northover2015-10-151-1/+1
| | | | llvm-svn: 250425
* Fix pr24486.Rafael Espindola2015-10-051-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
* [MC] Fix style bugs introduced in r247471. Reported by Rafael Espindola.Davide Italiano2015-09-111-3/+3
| | | | llvm-svn: 247483
* [MC] Don't crash on division by zero.Davide Italiano2015-09-111-1/+11
| | | | | | Differential Revision: http://reviews.llvm.org/D12776 llvm-svn: 247471
* MCExpr: Avoid UB by evaluating this shift as unsignedJustin Bogner2015-06-231-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
* MC: Add target hook to control symbol quotingMatt Arsenault2015-06-091-12/+18
| | | | llvm-svn: 239370
* MC: Clean up naming in MCObjectWriter. NFC.Jim Grosbach2015-06-041-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
* Remember if a weakref of a symbol has been used.Rafael Espindola2015-06-031-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
* MC: Clean up MCExpr naming. NFC.Jim Grosbach2015-05-301-31/+31
| | | | llvm-svn: 238634
* Remove getData.Rafael Espindola2015-05-291-6/+3
| | | | | | This completes the mechanical part of merging MCSymbol and MCSymbolData. llvm-svn: 238617
* Remove the MCSymbolData typedef.Rafael Espindola2015-05-291-2/+2
| | | | | | The getData member function is next. llvm-svn: 238611
* Move common symbol related information from MCSectionData to MCSymbol.Rafael Espindola2015-05-291-1/+1
| | | | llvm-svn: 238583
* Fix crash in MCExpr::print.Pete Cooper2015-05-291-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
* Remove a trivial forwarding function. NFC.Rafael Espindola2015-05-281-2/+2
| | | | llvm-svn: 238506
* Use operator<< instead of print in a few more places.Rafael Espindola2015-05-271-1/+1
| | | | llvm-svn: 238315
* Stop using MCSectionData in MCExpr.h.Rafael Espindola2015-05-261-2/+1
| | | | llvm-svn: 238163
* Return a MCSection from MCFragment::getParent().Rafael Espindola2015-05-261-3/+4
| | | | | | Another step in merging MCSectionData and MCSection. llvm-svn: 238162
* Move alignment from MCSectionData to MCSection.Rafael Espindola2015-05-211-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
* MC: Use MCSymbol in MCObjectWriter::isWeak(), NFCDuncan P. N. Exon Smith2015-05-201-2/+1
| | | | | | Continue to prefer `MCSymbol` when we need both. llvm-svn: 237798
* MC: Use MCSymbol in MCAsmLayout::getSymbolOffset(), NFCDuncan P. N. Exon Smith2015-05-191-2/+2
| | | | | | | Continue to canonicalize on MCSymbol instead of MCSymbolData when both are needed. llvm-svn: 237749
* MC: Clean up method names in MCContext.Jim Grosbach2015-05-181-1/+1
| | | | | | | The naming was a mish-mash of old and new style. Update to be consistent with the new. NFC. llvm-svn: 237594
* [Hexagon] Adding expression MC emission and removing XFAIL from test that ↵Colin LeMahieu2015-05-011-0/+12
| | | | | | hits this code path. llvm-svn: 236348
* [MC] Split MCBinaryExpr::Shr into LShr and AShr.Ahmed Bougacha2015-04-281-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
* MC: For variable symbols, maintain MCSymbol::Section as a cache.Peter Collingbourne2015-04-031-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
* Revert r233595, "MC: For variable symbols, maintain MCSymbol::Section as a ↵Peter Collingbourne2015-04-021-3/+0
| | | | | | cache." llvm-svn: 233898
* MC: For variable symbols, maintain MCSymbol::Section as a cache.Peter Collingbourne2015-03-301-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
* Fix PR23025.Rafael Espindola2015-03-261-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
* clang-format bits of code to make another patch readable.Rafael Espindola2015-03-251-18/+11
| | | | llvm-svn: 233203
* Fix fixup evaluation when deciding what to relocate with.Rafael Espindola2015-03-251-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
* Produce an error instead of asserting on invalid .sleb128/.uleb128.Rafael Espindola2015-03-251-7/+4
| | | | llvm-svn: 233155
* Expand variables when evaluating absolute expressions.Rafael Espindola2015-03-041-1/+1
| | | | | | | This allows for variables to be used in .size. This matches gnu AS functionality. llvm-svn: 231295
* [MC][Target] Implement support for R_X86_64_SIZE{32,64}.Davide Italiano2015-03-041-0/+2
| | | | | | | Differential Revision: D7990 Reviewed by: rafael, majnemer llvm-svn: 231216
* ARM: add support for segment base relocations (SBREL)Saleem Abdulrasool2015-01-111-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
* Instead of explicitely comparing both lowercase and uppercase variants.Roman Divacky2014-12-181-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
* Add a corresponding '@LOCAL' parse to match r224415.Justin Hibbits2014-12-181-0/+1
| | | | | | Pointed out by Jim Grosbach. llvm-svn: 224494
* Add parsing of 'foo@local".Justin Hibbits2014-12-171-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
* Add support for small-model PIC for PowerPC.Justin Hibbits2014-11-121-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
* MC: Shrink MCSymbolRefExpr by only storing the bits we need.Benjamin Kramer2014-10-111-8/+19
| | | | | | 32 -> 16 bytes on x86_64. NFC. llvm-svn: 219574
* MC: Use @IMGREL instead of @IMGREL32, which we can't parseReid Kleckner2014-09-251-1/+1
| | | | | | | | | | | | Nico Rieck added support for this 32-bit COFF relocation some time ago for Win64 stuff. It appears that as an oversight, the assembly output used "foo"@IMGREL32 instead of "foo"@IMGREL, which is what we can parse. Sadly, there were actually tests that took in IMGREL and put out IMGREL32, and we didn't notice the inconsistency. Oh well. Now LLVM can assemble it's own output with slightly more fidelity. llvm-svn: 218437
* Add a helper to MCExpr for when an expression is know to be absolute.Rafael Espindola2014-08-151-6/+20
| | | | llvm-svn: 215713
* Fix tabs.Joerg Sonnenberger2014-08-101-4/+4
| | | | llvm-svn: 215311
* If available, pass down the Fixup object to EvaluateAsRelocatable.Joerg Sonnenberger2014-08-101-16/+23
| | | | | | | At least on PowerPC, the interpretation of certain modifiers depends on the context they appear in. llvm-svn: 215310
* [mips][mips64r6] Add Relocations R_MIPS_PCHI16, R_MIPS_PCLO16 Zoran Jovanovic2014-05-271-0/+2
| | | | | | Differential Revision: http://reviews.llvm.org/D3860 llvm-svn: 209659
* Fix pr19645.Rafael Espindola2014-05-031-2/+1
| | | | | | | | | | | | | | | | The fix itself is fairly simple: move getAccessVariant to MCValue so that we replace the old weak expression evaluation with the far more general EvaluateAsRelocatable. This then requires that EvaluateAsRelocatable stop when it finds a non trivial reference kind. And that in turn requires the ELF writer to look harder for weak references. Last but not least, this found a case where we were being bug by bug compatible with gas and accepting an invalid input. I reported pr19647 to track it. llvm-svn: 207920
* Parse and create GOT_PREL relocations.Joerg Sonnenberger2014-04-291-0/+2
| | | | llvm-svn: 207526
* Add an option for evaluating past symbols.Rafael Espindola2014-04-281-17/+26
| | | | | | | | | | | | | When evaluating an assembly expression for a relocation, we want to stop at MCSymbols that are in the symbol table, even if they are variables. This is needed since the semantics may require that the relocation use them. That is not the case when computing the value of a symbol in the symbol table. There are no relocations in this case and we have to keep going until we hit a section or find out that the expression doesn't have an assembly time value. llvm-svn: 207445
OpenPOWER on IntegriCloud