aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/ELFObjectWriter.cpp
AgeCommit message (Collapse)AuthorFilesLines
2015-01-06Revert r225048: It broke ObjC on AArch64.Lang Hames1-4/+6
I've filed http://llvm.org/PR22100 to track this issue. llvm-svn: 225228
2014-12-31Add r224985 back with a fix.Rafael Espindola1-6/+4
The issues was that AArch64 has additional restrictions on when local relocations can be used. We have to take those into consideration when deciding to put a L symbol in the symbol table or not. Original message: Remove doesSectionRequireSymbols. In an assembly expression like bar: .long L0 + 1 the intended semantics is that bar will contain a pointer one byte past L0. In sections that are merged by content (strings, 4 byte constants, etc), a single position in the section doesn't give the linker enough information. For example, it would not be able to tell a relocation must point to the end of a string, since that would look just like the start of the next. The solution used in ELF to use relocation with symbols if there is a non-zero addend. In MachO before this patch we would just keep all symbols in some sections. This would miss some cases (only cstrings on x86_64 were implemented) and was inefficient since most relocations have an addend of 0 and can be represented without the symbol. This patch implements the non-zero addend logic for MachO too. llvm-svn: 225048
2014-12-31Revert "Remove doesSectionRequireSymbols."Rafael Espindola1-4/+6
This reverts commit r224985. I am investigating why it made an Apple bot unhappy. llvm-svn: 225044
2014-12-30Remove doesSectionRequireSymbols.Rafael Espindola1-6/+4
In an assembly expression like bar: .long L0 + 1 the intended semantics is that bar will contain a pointer one byte past L0. In sections that are merged by content (strings, 4 byte constants, etc), a single position in the section doesn't give the linker enough information. For example, it would not be able to tell a relocation must point to the end of a string, since that would look just like the start of the next. The solution used in ELF to use relocation with symbols if there is a non-zero addend. In MachO before this patch we would just keep all symbols in some sections. This would miss some cases (only cstrings on x86_64 were implemented) and was inefficient since most relocations have an addend of 0 and can be represented without the symbol. This patch implements the non-zero addend logic for MachO too. llvm-svn: 224985
2014-10-17Add back commits r219835 and a fixed version of r219829.Rafael Espindola1-48/+26
The only difference from r219829 is using getOrCreateSectionSymbol(*ELFSec) instead of GetOrCreateSymbol(ELFSec->getSectionName()) in ELFObjectWriter which causes us to use the correct section symbol even if we have multiple sections with the same name. Original messages: r219829: Correctly handle references to section symbols. When processing assembly like .long .text we were creating a new undefined symbol .text. GAS on the other hand would handle that as a reference to the .text section. This patch implements that by creating the section symbols earlier so that they are visible during asm parsing. The patch also updates llvm-readobj to print the symbol number in the relocation dump so that the test can differentiate between two sections with the same name. r219835: Allow forward references to section symbols. llvm-svn: 220021
2014-10-17Revert commit r219835 and r219829.Rafael Espindola1-26/+48
Revert "Correctly handle references to section symbols." Revert "Allow forward references to section symbols." Rui found a regression I am debugging. llvm-svn: 220010
2014-10-15Correctly handle references to section symbols.Rafael Espindola1-48/+26
When processing assembly like .long .text we were creating a new undefined symbol .text. GAS on the other hand would handle that as a reference to the .text section. This patch implements that by creating the section symbols earlier so that they are visible during asm parsing. The patch also updates llvm-readobj to print the symbol number in the relocation dump so that the test can differentiate between two sections with the same name. llvm-svn: 219829
2014-10-15Simplify handling of --noexecstack by using getNonexecutableStackSection.Rafael Espindola1-7/+0
llvm-svn: 219799
2014-10-06Note that a gold bug has been fixed.Rafael Espindola1-2/+3
We should be able to stop working around it at some point in the future. llvm-svn: 219115
2014-09-29WinCOFFObjectWriter: optimize the string table for common sufficesHans Wennborg1-2/+2
This is a follow-up from r207670 which did the same for ELF. Differential Revision: http://reviews.llvm.org/D5530 llvm-svn: 218636
2014-09-19Elide unnecessary DenseMap copy.Benjamin Kramer1-3/+3
No functionality change. llvm-svn: 218122
2014-07-20[MC] Pass MCSymbolData to needsRelocateWithSymbolUlrich Weigand1-1/+1
As discussed in a previous checking to support the .localentry directive on PowerPC, we need to inspect the actual target symbol in needsRelocateWithSymbol to make the appropriate decision based on that symbol's st_other bits. Currently, needsRelocateWithSymbol does not get the target symbol. However, it is directly available to its sole caller. This patch therefore simply extends the needsRelocateWithSymbol by a new parameter "const MCSymbolData &SD", passes in the target symbol, and updates all derived implementations. In particular, in the PowerPC implementation, this patch removes the FIXME added by the previous checkin. llvm-svn: 213487
2014-07-08Mips.abiflags is a new implicitly generated section that will be present on ↵Vladimir Medic1-0/+1
all new modules. The section contains a versioned data structure which represents essentially information to allow a program loader to determine the requirements of the application. This patch implements mips.abiflags section and provides test cases for it. llvm-svn: 212519
2014-07-03Invert the MC -> Object dependency.Rafael Espindola1-1/+1
Now that we have a lib/MC/MCAnalysis, the dependency was there just because of two helper classes. Move the two over to MC. This will allow IRObjectFile to parse inline assembly. llvm-svn: 212248
2014-06-19Convert some assert(0) to llvm_unreachable or fold an 'if' condition into ↵Craig Topper1-2/+1
the assert. llvm-svn: 211254
2014-06-14Using llvm::sys::swapByteOrder() for the common case of byte-swapping a ↵Artyom Skrobov1-1/+1
value in place llvm-svn: 210978
2014-06-14Renaming SwapByteOrder() to getSwappedBytes()Artyom Skrobov1-1/+1
The next commit will add swapByteOrder(), acting in-place llvm-svn: 210973
2014-05-03Fix pr19645.Rafael Espindola1-2/+21
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
2014-05-01Move getBaseSymbol somewhere the COFF writer can use.Rafael Espindola1-26/+3
I will use it there in a second. llvm-svn: 207761
2014-05-01Make getBaseSymbol non recursive.Rafael Espindola1-3/+5
llvm-svn: 207759
2014-04-30Provide a version of getSymbolOffset that returns false on error.Rafael Espindola1-24/+6
This simplifies ELFObjectWriter::SymbolValue a bit more. This new version will also be used in the COFF writer to fix pr19147. llvm-svn: 207711
2014-04-30Simplify ELFObjectWriter::SymbolValue.Rafael Espindola1-22/+14
It now defers all offset computation to getSymbolOffset. llvm-svn: 207674
2014-04-30ELFObjectWriter: deduplicate suffices in strtabHans Wennborg1-86/+32
We already do this for shstrtab, so might as well do it for strtab. This extracts the string table building code into a separate class. The idea is to use it for other object formats too. I mostly wanted to do this for the general principle, but it does save a little bit on object file size. I tried this on a clang bootstrap and saved 0.54% on the sum of object file sizes (1.14 MB out of 212 MB for a release build). Differential Revision: http://reviews.llvm.org/D3533 llvm-svn: 207670
2014-04-29Centralize the handling of the thumb bit.Rafael Espindola1-8/+9
This patch centralizes the handling of the thumb bit around MCStreamer::isThumbFunc and makes isThumbFunc handle aliases. This fixes a corner case, but the main advantage is having just one way to check if a MCSymbol is thumb or not. This should still be refactored to be ARM only, but at least now it is just one predicate that has to be refactored instead of 3 (isThumbFunc, ELF_Other_ThumbFunc, and SF_ThumbFunc). llvm-svn: 207522
2014-04-28Add an option for evaluating past symbols.Rafael Espindola1-2/+2
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
2014-04-28Simplify ELFObjectWriter::ExecutePostLayoutBinding.Rafael Espindola1-3/+6
No functionality change. This removes the last use of AliasedSymbol in ELFObjectWriter.cpp. llvm-svn: 207424
2014-04-28Simplify isLocal().Rafael Espindola1-11/+6
No functionality change. llvm-svn: 207421
2014-04-28Don't include an invalid symbol in the symbol table.Rafael Espindola1-8/+10
The symbol table itself has no relocations, so it is not possible to represent things like a = undefined + 1 With the patch we just omit these variables. That matches the behaviour of the gnu assembler. llvm-svn: 207419
2014-04-28Produce an error instead of a crash in an expr we cannot represent.Rafael Espindola1-1/+6
llvm-svn: 207414
2014-04-25Fix quadratic performance during debug compression due to sections x symbols ↵David Blaikie1-12/+21
iteration. When fixing the symbols in each compressed section we were iterating over all symbols for each compressed section. In extreme cases this could snowball severely (5min uncompressed -> 35min compressed) due to iterating over all symbols for each compressed section (large numbers of compressed sections can be generated by DWARF type units). To address this, build a map of the symbols in each section ahead of time, and access that map if a section is being compressed. This brings compile time for the aforementioned example down to ~6 minutes. llvm-svn: 207167
2014-04-24Spread some const around for non-mutating uses of MCSymbolData.David Blaikie1-1/+1
I discovered this const-hole while attempting to coalesnce the Symbol and SymbolMap data structures. There's some pending issues with that, but I figured this change was easy to flush early. llvm-svn: 207124
2014-04-23Centralize handling of ELF_Other_ThumbFunc.Rafael Espindola1-3/+2
No functionality change. llvm-svn: 206988
2014-04-22Follow aliases when determining if a symbol is thumb.Rafael Espindola1-2/+1
This fixes pr19484. llvm-svn: 206917
2014-04-19Add parens to appease GCC warning.David Blaikie1-4/+4
llvm-svn: 206678
2014-04-18Compress debug sections only when beneficial.David Blaikie1-2/+6
Both ZLIB and the debug info compressed section header ("ZLIB" + the size of the uncompressed data) take some constant overhead so in some cases the compressed data is actually larger than the uncompressed data. In these cases, just don't compress or rename the section at all. llvm-svn: 206659
2014-04-18Update the fragments of symbols in compressed sections.David Blaikie1-0/+21
While unnamed relocations are already cached in side tables in ELFObjectWriter::RecordRelocation, symbols still need their fragments updated to refer to the newly compressed fragment (even if that fragment isn't big enough to fit the offset). Even though we only create temporary symbols in debug info sections this comes up in 32 bit builds where even temporary symbols in mergeable sections (such as debug_str) have to be emitted as named symbols. I tried a few other ways to do this but they all didn't work for various reasons: 1) Canonicalize the MCSymbolData in RecordRelocation, nulling out the Fragment (so it didn't have to be updated by CompressDebugSection). This doesn't work because some code relies on symbols having fragments to indicate that they're defined, I think. 2) Canonicalize the MCSymbolData in RecordRelocation to be "first fragment + absolute offset" so it would be cheaper to just test and update the fragment in CompressDebugSections. This doesn't work because the offset computed in RecordRelocation isn't that of the symbol's fragment, it's the passed in fragment (I haven't figured out what that fragment is - perhaps it's the location where the relocation is to be written). And if the fragment offset has to be computed only for this use we might as well just do it when we need to, in CompressDebugSection. I also added an assert to help catch this a bit more clearly, even though it is UB. The test case improvements would either assert fail and/or valgrind vail without the fix, even if they wouldn't necessarily fail the FileCheck output. llvm-svn: 206653
2014-04-18Add range access to MCAssembler's symbol collection.David Blaikie1-16/+14
llvm-svn: 206631
2014-04-13[C++11] More 'nullptr' conversion or in some cases just using a boolean ↵Craig Topper1-2/+2
check instead of comparing to nullptr. llvm-svn: 206129
2014-04-11Format fixes for r205990David Blaikie1-5/+12
llvm-svn: 206078
2014-04-11Don't lose the thumb bit by using relocations with sections.Rafael Espindola1-0/+7
This fixes a regression from r205076. llvm-svn: 206047
2014-04-10Reimplement debug info compression by compressing the whole section, rather ↵David Blaikie1-0/+114
than a fragment. To support compressing the debug_line section that contains multiple fragments (due, I believe, to variation in choices of line table encoding depending on the size of instruction ranges in the actual program code) we needed to support compressing multiple MCFragments in a single pass. This patch implements that behavior by mutating the post-relaxed and relocated section to be the compressed form of its former self, including renaming the section. This is a more flexible (and less invasive, to a degree) implementation that will allow for other features such as "use compression only if it's smaller than the uncompressed data". Compressing debug_frame would be a possible further extension to this work, but I've left it for now. The hurdle there is alignment sections - which might require going as far as to refactor MCAssembler.cpp:writeFragment to handle writing to a byte buffer or an MCObjectWriter (there's already a virtual call there, so it shouldn't add substantial compile-time cost) which could in turn involve refactoring MCAsmBackend::writeNopData to use that same abstraction... which involves touching all the backends. This would remove the limited handling of fragment writing seen in ELFObjectWriter.cpp:getUncompressedData which would be nice - but it's more invasive. I did discover that I (perhaps obviously) don't need to handle relocations when I rewrite the fragments - since the relocations have already been applied and computed (and stored into ELFObjectWriter::Relocations) by this stage (necessarily, because we need to have written any immediate values or assembly-time relocations into the data already before we compress it, which we have). The test case doesn't necessarily cover that in detail - I can add more test coverage if that's preferred. llvm-svn: 205990
2014-04-02Work around gold bug http://sourceware.org/PR16794.Rafael Espindola1-0/+5
llvm-svn: 205416
2014-03-29Completely rewrite ELFObjectWriter::RecordRelocation.Rafael Espindola1-160/+226
I started trying to fix a small issue, but this code has seen a small fix too many. The old code was fairly convoluted. Some of the issues it had: * It failed to check if a symbol difference was in the some section when converting a relocation to pcrel. * It failed to check if the relocation was already pcrel. * The pcrel value computation was wrong in some cases (relocation-pc.s) * It was missing quiet a few cases where it should not convert symbol relocations to section relocations, leaving the backends to patch it up. * It would not propagate the fact that it had changed a relocation to pcrel, requiring a quiet nasty work around in ARM. * It was missing comments. llvm-svn: 205076
2014-03-27Remove another unused argument.Rafael Espindola1-6/+3
llvm-svn: 204961
2014-03-27Remove unused argument.Rafael Espindola1-1/+1
llvm-svn: 204956
2014-03-27Correctly propagates st_size.Rafael Espindola1-7/+6
This also finally removes a bogus call to AliasedSymbol. llvm-svn: 204883
2014-03-26Correctly detect if a symbol uses a reserved section index or not.Rafael Espindola1-3/+5
The logic was incorrect for variables, causing them to end up in the wrong section if the section had an index >= 0xff00. llvm-svn: 204771
2014-03-25Create .symtab_shndxr only when needed.Rafael Espindola1-86/+120
We need .symtab_shndxr if and only if a symbol references a section with an index >= 0xff00. The old code was trying to figure out if the section was needed ahead of time, making it a fairly dependent on the code actually writing the table. It was also somewhat conservative and would create the section in cases where it was not needed. If I remember correctly, the old structure was there so that the sections were created in the same order gas creates them. That was valuable when MC's support for ELF was new and we tested with elf-dump.py. This patch refactors the symbol table creation to another class and makes it obvious that .symtab_shndxr is really only created when we are about to output a reference to a section index >= 0xff00. While here, also improve the tests to use macros. One file is one section short of needing .symtab_shndxr, the second one has just the right number. llvm-svn: 204769
2014-03-25Use Endian.h to simplify this code a bit.Rafael Espindola1-104/+64
While at it, factor some logic into FragmentWriter. This will allow more code to be factored out of the fairly large ELFObjectWriter. llvm-svn: 204765
2014-03-24Propagate section from base to derived symbol.Rafael Espindola1-18/+19
We were already propagating the section in a = b With this patch we also propagate it for a = b + 1 llvm-svn: 204581