summaryrefslogtreecommitdiffstats
path: root/llvm/lib/MC/ELFObjectWriter.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Simplify interface now that we don't need to pass IsPCRel. NFC.Rafael Espindola2017-07-111-3/+7
| | | | llvm-svn: 307734
* Add a common error checking for some invalid expressions.Rafael Espindola2017-06-221-3/+0
| | | | | | | This refactors a bit of duplicated code and fixes an assertion failure on ELF. llvm-svn: 306035
* sink DebugCompressionType into MC for exposing to clangSaleem Abdulrasool2017-06-091-6/+10
| | | | | | | | | | | | | | This is a preparatory change to expose the debug compression style to clang. It requires exposing the enumeration and passing the actual value through to the backend from the frontend in actual value form rather than a boolean that selects the GNU style of debug info compression. Minor tweak to the ELF Object Writer to use a variable for re-used values. Add an assertion that debug information format is one of the two currently known types if debug information is being compressed. llvm-svn: 305038
* Move Object format code to lib/BinaryFormat.Zachary Turner2017-06-071-1/+1
| | | | | | | | | | | | This creates a new library called BinaryFormat that has all of the headers from llvm/Support containing structure and layout definitions for various types of binary formats like dwarf, coff, elf, etc as well as the code for identifying a file from its magic. Differential Revision: https://reviews.llvm.org/D33843 llvm-svn: 304864
* Sort the remaining #include lines in include/... and lib/....Chandler Carruth2017-06-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | I did this a long time ago with a janky python script, but now clang-format has built-in support for this. I fed clang-format every line with a #include and let it re-sort things according to the precise LLVM rules for include ordering baked into clang-format these days. I've reverted a number of files where the results of sorting includes isn't healthy. Either places where we have legacy code relying on particular include ordering (where possible, I'll fix these separately) or where we have particular formatting around #include lines that I didn't want to disturb in this patch. This patch is *entirely* mechanical. If you get merge conflicts or anything, just ignore the changes in this patch and run clang-format over your #include lines in the files. Sorry for any noise here, but it is important to keep these things stable. I was seeing an increasing number of patches with irrelevant re-ordering of #include lines because clang-format was used. This patch at least isolates that churn, makes it easy to skip when resolving conflicts, and gets us to a clean baseline (again). llvm-svn: 304787
* [MC] Fix some Clang-tidy modernize-use-using warnings; other minor fixes (NFC).Eugene Zelenko2017-04-261-4/+4
| | | | llvm-svn: 301485
* MC: Remove unused virtual function MCObjectWriter::isWeak. NFC.Peter Collingbourne2017-04-081-24/+1
| | | | llvm-svn: 299817
* Fix asm printing of associated sections.Evgeniy Stepanov2017-03-141-5/+9
| | | | | | | Make MCSectionELF::AssociatedSection be a link to a symbol, because that's how it works in the assembly, and use it in the asm printer. llvm-svn: 297769
* Silence a warning "hiding virtual function".Vassil Vassilev2017-03-061-0/+1
| | | | llvm-svn: 297018
* MC: De-duplicate the object streamer implementations of EmitFileDirective ↵Peter Collingbourne2017-03-031-0/+2
| | | | | | into MCObjectStreamer. NFCI. llvm-svn: 296912
* [MC] Fix some Clang-tidy modernize and Include What You Use warnings; other ↵Eugene Zelenko2017-02-111-14/+31
| | | | | | minor fixes (NFC). llvm-svn: 294813
* Make it possible to set SHF_LINK_ORDER explicitly.Rafael Espindola2017-02-091-2/+1
| | | | | | | This will make it possible to add support for gcing user metadata (asan for example). llvm-svn: 294589
* Change how we handle section symbols on ELF.Rafael Espindola2017-02-021-16/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | On ELF every section can have a corresponding section symbol. When in an assembly file we have .quad .text the '.text' refers to that symbol. The way we used to handle them is to leave .text an undefined symbol until the very end when the object writer would map them to the actual section symbol. The problem with that is that anything before the end would see an undefined symbol. This could result in bad diagnostics (test/MC/AArch64/label-arithmetic-diags-elf.s), or incorrect results when using the asm streamer (est/MC/Mips/expansion-jal-sym-pic.s). Fixing this will also allow using the section symbol earlier for setting sh_link of SHF_METADATA sections. This patch includes a few hacks to avoid changing our behaviour when handling conflicts between section symbols and other symbols. I reported pr31850 to track that. llvm-svn: 293936
* Recommit r292214 "[Support/Compression] - Change zlib API to return Error ↵George Rimar2017-01-171-4/+5
| | | | | | | | | | | | | | | | | | instead of custom status" No any changes, will follow up with D28807 commit containing APLi change for clang to fix build issues happened. Original commit message: [Support/Compression] - Change zlib API to return Error instead of custom status. Previously API returned custom enum values. Patch changes it to return Error with string description. That should help users to report errors in universal way. Differential revision: https://reviews.llvm.org/D28684 llvm-svn: 292226
* Revert r292214 "[Support/Compression] - Change zlib API to return Error ↵George Rimar2017-01-171-5/+4
| | | | | | | | | instead of custom status." It broked clang: http://lab.llvm.org:8080/green//job/clang-stage1-cmake-RA-incremental_build/34218/consoleFull#46141505449ba4694-19c4-4d7e-bec5-911270d8a58c llvm-svn: 292217
* [Support/Compression] - Change zlib API to return Error instead of custom ↵George Rimar2017-01-171-4/+5
| | | | | | | | | | | | status. Previously API returned custom enum values. Patch changes it to return Error with string description. That should help users to report errors in universal way. Differential revision: https://reviews.llvm.org/D28684 llvm-svn: 292214
* MC: ensure that we have a section before accessing itSaleem Abdulrasool2016-11-221-15/+17
| | | | | | | | | | | | We would attempt to access the symbol section without ensuring that the symbol was not absolute. When the assembler referenced relocation is not evaluated to the absolute, but when we record the relocation, we would query the section. Because the symbol is absolute, it does not have a section associated with it, triggering an assertion. Just be more careful about the access of the section. Addresses PR31064! llvm-svn: 287619
* Misc improvements to StringTableBuilder.Rafael Espindola2016-10-041-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch adds write methods to StringTableBuilder so that it is easier to change the underlying implementation. Using the write methods, avoid creating a temporary buffer when using mmaped output. It also uses a more compact key in the DenseMap. Overall this produces a slightly faster lld: firefox master 6.853419709 patch 6.841968912 1.00167361138x faster chromium master 4.297280174 patch 4.298712163 1.00033323147x slower chromium fast master 1.802335952 patch 1.806872459 1.00251701521x slower the gold plugin master 0.3247149 patch 0.321971644 1.00852017888x faster clang master 0.551279945 patch 0.543733194 1.01387951128x faster llvm-as master 0.032743458 patch 0.032143478 1.01866568391x faster the gold plugin fsds master 0.350814247 patch 0.348571741 1.00643341309x faster clang fsds master 0.6281672 patch 0.621130222 1.01132931187x faster llvm-as fsds master 0.030168899 patch 0.029797155 1.01247582194x faster scylla master 3.104222518 patch 3.059590248 1.01458766252x faster llvm-svn: 283266
* Delete some dead code.Rafael Espindola2016-06-211-8/+0
| | | | | | Found by gcc 6. llvm-svn: 273303
* Recommit 270977 - [llvm-mc] - Teach llvm-mc to generate zlib styled ↵George Rimar2016-05-271-19/+50
| | | | | | | | | | | | | | | | | | | | | | | | | | | compression sections. Fix: updated clang code which was not updated by mistake. Original commit message: [llvm-mc] - Teach llvm-mc to generate zlib styled compression sections. This patch is strongly based on previously reverted D20331. (because of gnuutils < 2.26 does not support compressed debug sections in non zlib-gnu style) Difference that this patch supports both zlib and zlib-gnu styles. -compress-debug-sections option now supports next values: -compress-debug-sections=zlib-gnu -compress-debug-sections=zlib -compress-debug-sections=none Previously specifying -compress-debug-sections enabled zlib-gnu compression, so anyone can put "-compress-debug-sections=zlib-gnu" to restore the behavior that was before this patch for case when compression was enabled. Differential revision: http://reviews.llvm.org/D20676 llvm-svn: 270987
* Revert r270977 ([llvm-mc] - Teach llvm-mc to generate zlib styled ↵George Rimar2016-05-271-50/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | compression sections.) It broke buildbot: http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/13585/steps/build/logs/stdio Initial commit message: [llvm-mc] - Teach llvm-mc to generate zlib styled compression sections. This patch is strongly based on previously reverted D20331. (because of gnuutils < 2.26 does not support compressed debug sections in non zlib-gnu style) Difference that this patch supports both zlib and zlib-gnu styles. -compress-debug-sections option now supports next values: -compress-debug-sections=zlib-gnu -compress-debug-sections=zlib -compress-debug-sections=none Previously specifying -compress-debug-sections enabled zlib-gnu compression, so anyone can put "-compress-debug-sections=zlib-gnu" to restore the behavior that was before this patch for case when compression was enabled. Differential revision: http://reviews.llvm.org/D20676 llvm-svn: 270978
* [llvm-mc] - Teach llvm-mc to generate zlib styled compression sections.George Rimar2016-05-271-19/+50
| | | | | | | | | | | | | | | | | | | | This patch is strongly based on previously reverted D20331. (because of gnuutils < 2.26 does not support compressed debug sections in non zlib-gnu style) Difference that this patch supports both zlib and zlib-gnu styles. -compress-debug-sections option now supports next values: -compress-debug-sections=zlib-gnu -compress-debug-sections=zlib -compress-debug-sections=none Previously specifying -compress-debug-sections enabled zlib-gnu compression, so anyone can put "-compress-debug-sections=zlib-gnu" to restore the behavior that was before this patch for case when compression was enabled. Differential revision: http://reviews.llvm.org/D20676 llvm-svn: 270977
* Revert r270569 (teach llvm-mc to generate compressed debug sections in zlibRichard Smith2016-05-251-21/+23
| | | | | | style). It appears that current ELF linkers are not ready for this. llvm-svn: 270638
* Recommit r270070 ([llvm-mc] - Teach llvm-mc to generate compressed debug ↵George Rimar2016-05-241-23/+21
| | | | | | | | | | | | | | | | | | | sections in zlib style.) Now, after landing r270560, r270557, r270320 it is a proper time. Original commit message: [llvm-mc] - Teach llvm-mc to generate compressed debug sections in zlib style. Before this patch llvm-mc generated zlib-gnu styled sections. That means no SHF_COMPRESSED flag was set, magic 'zlib' signature was used in combination with full size field. Sections were renamed to "*.z*". This patch reimplements the compression style to zlib one as zlib-gnu looks to be depricated everywhere. Differential revision: http://reviews.llvm.org/D20331 llvm-svn: 270569
* Temporarily revert r270070George Rimar2016-05-191-21/+23
| | | | | | | | | | | | | | | | | | | | | | It broke buildbot: http://lab.llvm.org:8011/builders/clang-s390x-linux/builds/4817/steps/ninja%20check%201/logs/stdio Actually it is just because D20273 not yet commited, but these 2 were crossing with each other, and I`ll better find the way to land them separatelly soon. Initial commit message: [llvm-mc] - Teach llvm-mc to generate compressed debug sections in zlib style. Before this patch llvm-mc generated zlib-gnu styled sections. That means no SHF_COMPRESSED flag was set, magic 'zlib' signature was used in combination with full size field. Sections were renamed to "*.z*". This patch reimplements the compression style to zlib one as zlib-gnu looks to be depricated everywhere. Differential revision: http://reviews.llvm.org/D20331 llvm-svn: 270075
* [llvm-mc] - Teach llvm-mc to generate compressed debug sections in zlib style.George Rimar2016-05-191-23/+21
| | | | | | | | | | | | Before this patch llvm-mc generated zlib-gnu styled sections. That means no SHF_COMPRESSED flag was set, magic 'zlib' signature was used in combination with full size field. Sections were renamed to "*.z*". This patch reimplements the compression style to zlib one as zlib-gnu looks to be depricated everywhere. Differential revision: http://reviews.llvm.org/D20331 llvm-svn: 270070
* [mips] Correct the ordering of HI/LO pairs in the relocation table.Daniel Sanders2016-05-061-5/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: There seems to have been a misunderstanding as to the meaning of 'offset' in the rules laid down by our ABI. The previous code believed that 'offset' meant the offset within the section that the relocation is applied to. However, it should have meant the offset from the symbol used in the relocation expression. This patch adds two fields to ELFRelocationEntry and uses them to correct the order of relocations for MIPS. These fields contain: * The original symbol before shouldRelocateWithSymbol() is considered. This ensures that R_MIPS_GOT16 is able to correctly distinguish between local and external symbols, allowing us to tell whether %got() requires a matching %lo() or not (local symbols require one, external symbols don't). It also prevents confusing cases where the fuzzy matching rules cause things like %hi(foo)/%lo(foo+3) and %hi(bar)/%lo(bar+1) to swap their %lo()'s. * The original offset before shouldRelocateWithSymbol() is considered. The existing Addend field is always zero when the object uses in place addends (because it's already moved it to the encoding) but MIPS needs to use the original offset to ensure that the linker correctly calculates the carry-in bit for %hi() and %got(). IAS ensures that unmatchable %hi()/%got() relocations are placed at the end of the table to ensure that the linker rejects the table (we're unable to report such errors directly). The alternatives to this risk accidental matching against inappropriate relocations which may silently compute incorrect values due to an incorrect carry bit between the %lo() and %hi()/%got(). Reviewers: sdardis Subscribers: dsanders, sdardis, rafael, llvm-commits Differential Revision: http://reviews.llvm.org/D19718 llvm-svn: 268733
* [mips] Use MipsMCExpr instead of MCSymbolRefExpr for all relocations.Daniel Sanders2016-05-031-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* [MC/ELFObjectWriter] Fix indentation of class body.David Blaikie2016-04-121-131/+130
| | | | llvm-svn: 266136
* Handle section vs global name conflict.Evgeniy Stepanov2016-03-281-1/+16
| | | | | | | | | | | | | This is a fix for PR26941. When there is both a section and a global definition with the same name, the global wins. Section symbols are not added to the symbol table; section references are left undefined and fixed up in the object writer unless they've been satisfied by some other definition. llvm-svn: 264649
* Fix Clang-tidy readability-redundant-control-flow warnings; other minor fixes.Eugene Zelenko2016-02-021-3/+2
| | | | | | Differential revision: http://reviews.llvm.org/D16793 llvm-svn: 259539
* Accept subtractions involving a weak symbol.Rafael Espindola2016-01-201-6/+0
| | | | | | | | | | | | | | | | | | When a symbol S shows up in an expression in assembly there are two possible interpretations * The expression is referring to the value of S in this file. * The expression is referring to the value after symbol resolution. In the first case the assembler can reason about the value and try to produce a relocation. In the second case, that is only possible if the symbol cannot be preempted. Assemblers are not very consistent about which interpretation gets used. This changes MC to agree with GAS in the case of an expression of the form "Sym - WeakSym". llvm-svn: 258329
* Handle 64 bit offsets.Rafael Espindola2016-01-191-1/+1
| | | | | | | | | No tests since llvm-mc takes 14 seconds on it. I will try to improve it and then test. Part of pr26208. llvm-svn: 258129
* Convert a few assert failures into proper errors.Rafael Espindola2016-01-131-4/+4
| | | | | | Fixes PR25944. llvm-svn: 257697
* Simplify. NFC.Rafael Espindola2016-01-131-9/+9
| | | | llvm-svn: 257689
* Avoid explicit relocation sorting most of the time.Rafael Espindola2015-12-171-17/+6
| | | | | | | | | | These days relocations are created and stored in a deterministic way. The order they are created is also suitable for the .o file, so we don't need an explicit sort. The last remaining exception is MIPS. llvm-svn: 255902
* Always sort by offset first. NFC.Rafael Espindola2015-12-171-0/+16
| | | | | | | Every target changing sortRelocs was first calling the parent implementation. Just run that first. llvm-svn: 255898
* [Assembler] Make fatal assembler errors non-fatalOliver Stannard2015-11-171-10/+20
| | | | | | | | | | | | | | Currently, if the assembler encounters an error after parsing (such as an out-of-range fixup), it reports this as a fatal error, and so stops after the first error. However, for most of these there is an obvious way to recover after emitting the error, such as emitting the fixup with a value of zero. This means that we can report on all of the errors in a file, not just the first one. MCContext::reportError records the fact that an error was encountered, so we won't actually emit an object file with the incorrect contents. Differential Revision: http://reviews.llvm.org/D14717 llvm-svn: 253328
* Add a RAW mode to StringTableBuilder.Rafael Espindola2015-10-231-2/+2
| | | | | | | | | | | | In this mode it just tries to tail merge the strings without imposing any other format constrains. It will not, for example, add a null byte between them. Also add support for keeping a tentative size and offset if we decide to not optimize after all. This will be used shortly in lld for merging SHF_STRINGS sections. llvm-svn: 251153
* Avoid storing a second copy of each string in StringTableBuilder.Rafael Espindola2015-10-221-3/+8
| | | | | | This was only use in the extremely uncommon case of @@@ symbols on ELF. llvm-svn: 251039
* Fix pr24486.Rafael Espindola2015-10-051-3/+0
| | | | | | | | | | | | | | | | | | 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] Allow MCObjectWriter's output stream to be swapped outDavid Majnemer2015-09-011-55/+32
| | | | | | | | | | | | | | | | | | There are occasions where it is useful to consider the entirety of the contents of a section. For example, compressed debug info needs the entire section available before it can compress it and write it out. The compressed debug info scenario was previously implemented by mirroring the implementation of writeSectionData in the ELFObjectWriter. Instead, allow the output stream to be swapped on demand. This lets callers redirect the output stream to a more convenient location before it hits the object file. No functionality change is intended. Differential Revision: http://reviews.llvm.org/D12509 llvm-svn: 246554
* Convert a member variable to a local one.Rafael Espindola2015-07-021-3/+3
| | | | llvm-svn: 241284
* Diagnose undefined temporary symbols.Rafael Espindola2015-06-251-0/+5
| | | | | | | | | | | | We already disallowed .global .Lfoo so this is reasonable. This is a small cherry pick from r240130. llvm-svn: 240681
* Revert r240302 ("Bring r240130 back.").Daniel Jasper2015-06-231-10/+3
| | | | | | | | | | | | | This causes errors like: ld: error: blah.o: requires dynamic R_X86_64_PC32 reloc against '' which may overflow at runtime; recompile with -fPIC blah.cc:function f(): error: undefined reference to '' blah.o:g(): error: undefined reference to '' I have not yet come up with an appropriate reproduction. llvm-svn: 240394
* Revert r240137 (Fixed/added namespace ending comments using clang-tidy. NFC)Alexander Kornienko2015-06-231-1/+1
| | | | | | Apparently, the style needs to be agreed upon first. llvm-svn: 240390
* Fix PR23914.Evgeniy Stepanov2015-06-221-1/+1
| | | | | | | r226830 moved the declaration of Buf to a nested scope, resulting in a dangling reference (in StringRef Name), and a use-after-free. llvm-svn: 240357
* Bring r240130 back.Rafael Espindola2015-06-221-3/+10
| | | | | | | | | | | | | | | | | | | | | | Now that pr23900 is fixed, we can bring it back with no changes. Original message: Make all temporary symbols unnamed. What this does is make all symbols that would otherwise start with a .L (or L on MachO) unnamed. Some of these symbols still show up in the symbol table, but we can just make them unnamed. In order to make sure we produce identical results when going thought assembly, all .L (not just the compiler produced ones), are now unnamed. Running llc on llvm-as.opt.bc, the peak memory usage goes from 208.24MB to 205.57MB. llvm-svn: 240302
* Update ELFObjectWriter::reset() following r238073.Yaron Keren2015-06-201-0/+1
| | | | llvm-svn: 240218
* Revert 240130, it caused crashes (repro in PR23900).Nico Weber2015-06-191-10/+3
| | | | llvm-svn: 240193
OpenPOWER on IntegriCloud