summaryrefslogtreecommitdiffstats
path: root/lld/ELF/SyntheticSections.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* [ELF] Correct sh_info for static symbol tablePeter Smith2017-01-241-5/+7
| | | | | | | | | | | | | The sh_info field of the SHT_SYMTAB section holds the index for the first non-local symbol. When there are global symbols that are output with STB_LOCAL binding due to having hidden visibility or matching the local version from a version script, the calculated value of NumLocals + 1 does not account for them. This change accounts for global symbols being output with local binding. Differential Revision: https://reviews.llvm.org/D28950 llvm-svn: 292910
* Do not allocate space for common symbols with -rRui Ueyama2017-01-241-2/+11
| | | | | | | | | | | | | | | Currently ld.lld -r allocates space for common symbols, whereas ld.bfd -r doesn't. As a result the OpenBSD makefile bits for creating libraries fail as they use ld -X -r to strip local symbols, which results in duplicate symbol errors because space for the common symbols has been allocated. The diff also implements the --define-commons option such that allocation of commons can be forced even if -r is used. Patch by Mark Kettenis. llvm-svn: 292878
* [ELF] - Stop handling local symbols in a special way.George Rimar2017-01-231-32/+42
| | | | | | | | | | | | | | | | | | | | Previously we stored kept locals in a KeptLocalSyms arrays, belonged to files. Patch makes SymbolTableSection to store locals in Symbols member, that already present and was used for globals. SymbolTableSection already had NumLocals counter member, so change itself is trivial. That allows to simplify handling of -r, Body::DynsymIndex is no more used as "symbol table index" for relocatable output. Change was suggested during review of D28773 and opens road for D28612. Differential revision: https://reviews.llvm.org/D29021 llvm-svn: 292789
* Add a isInCurrentDSO helper. NFC.Rafael Espindola2017-01-171-2/+2
| | | | llvm-svn: 292228
* [ELF][MIPS] Exclude mips .got from PT_GNU_RELRO segmentSimon Atanasyan2017-01-161-1/+1
| | | | | | | | | | | | | On MIPS .got section cannot be included into the PT_GNU_RELRO segment. Sometimes it might work, but in general it is unsupported. One of the problem is that all sections marked by SHF_MIPS_GPREL should be grouped together because data in these sections is addressable with a gp relative address, but such sections might be writable. This patch exclude mips .got from PT_GNU_RELRO segment and group SHF_MIPS_GPREL sections. llvm-svn: 292161
* Don't add DT_INIT/DT_FINI for undef and shared symbols.Rafael Espindola2017-01-131-2/+2
| | | | | | | | | | The freebsd dynamic linker doesn't check if the value is null (and it is reasonable for it to do that). That means that producing a .so with a null DT_INIT/DT_FINI causes the base address to be called. This should fix the libreoffice build. llvm-svn: 291944
* Inline a simple accessor function.Rui Ueyama2017-01-101-10/+7
| | | | llvm-svn: 291602
* Give local binding to VER_NDX_LOCAL symbols.Rafael Espindola2017-01-101-9/+1
| | | | | | | We were already dropping them from the dynamic symbol table, but the regular symbol table was still listing them as globals. llvm-svn: 291573
* ELF: Reserve space for copy relocations of read-only symbols in relro.Peter Collingbourne2017-01-101-3/+5
| | | | | | | | | | | | | | When reserving copy relocation space for a shared symbol, scan the DSO's program headers to see if the symbol is in a read-only segment. If so, reserve space for that symbol in a new synthetic section named .bss.rel.ro which will be covered by the relro program header. This fixes the security issue disclosed on the binutils mailing list at: https://sourceware.org/ml/libc-alpha/2016-12/msg00914.html Differential Revision: https://reviews.llvm.org/D28272 llvm-svn: 291524
* De-template DefinedSynthetic.Rui Ueyama2016-12-211-1/+1
| | | | | | | | DefinedSynthetic is not created for a real ELF object, so it doesn't have to be a template function. It has a virtual st_value, which is either 32 bit or 64 bit, but we can simply use 64 bit. llvm-svn: 290241
* [ELF][MIPS] Allow .MIPS.abiflags larger than one Elf_Mips_ABIFlags structSimon Atanasyan2016-12-211-2/+7
| | | | | | | | | | | Older versions of BFD generate libraries with .MIPS.abiflags that only concatenate the individual .MIPS.abiflags sections instead of merging. Patch by Alexander Richardson. Differential revision: https://reviews.llvm.org/D27770 llvm-svn: 290237
* Remove lld/Support/Memory.h.Rui Ueyama2016-12-181-1/+1
| | | | | | | | | | | | I thought for a while about how to remove it, but it looks like we can just copy the file for now. Of course I'm not happy about that, but it's just less than 50 lines of code, and we already have duplicate code in Error.h and some other places. I want to solve them all at once later. Differential Revision: https://reviews.llvm.org/D27819 llvm-svn: 290062
* [ELF] - Apply format (2). NFC.George Rimar2016-12-151-2/+4
| | | | llvm-svn: 289824
* [ELF] - Partial support of --gdb-index command line option (Part 3).George Rimar2016-12-151-8/+79
| | | | | | | | | | | | | Patch continues work started in D24706 and D25821. in this patch symbol table and constant pool areas were added to .gdb_index section output. This one finishes the implementation of --gdb-index functionality in LLD. Differential revision: https://reviews.llvm.org/D26283 llvm-svn: 289810
* [ELF] - Partial support of --gdb-index command line option (Part 2).George Rimar2016-12-151-12/+38
| | | | | | | | | | Patch continues work started in D24706, in this patch address area was added to .gdb_index section output. Differential revision: https://reviews.llvm.org/D25821 llvm-svn: 289790
* [ELF][MIPS] Fix .MIPS.options ri_gp_value on MIPS64Simon Atanasyan2016-12-121-1/+2
| | | | | | | | | | | The VA of _gp was being truncated to 32 bits when calling getVa(), but for 64bit MIPS we need to write a 64 bit value to .MIPS.options. Patch by Alexander Richardson. Differential revision: https://reviews.llvm.org/D27672 llvm-svn: 289432
* [ELF][I386] .got.plt entries for i386 should use VA of ifunc resolverPeter Smith2016-12-091-5/+1
| | | | | | | | | | | | | | | | | | The i386 glibc ld.so expects the .got.slot entry that is relocated by a R_386_IRELATIVE relocation to point directly at the ifunc resolver and not the address of the PLT entry + 6 (thus entering the lazy resolver). This is also the case for ARM and I suspect it is because these use REL relocations and can't use the addend field to store the address of the ifunc resolver. If the lazy resolver is used we get an error message stating that only R_386_JUMP_SLOT is supported. As ARM and i386 share the same code, I've removed the ARM specific test and added a writeIgotPlt() function that by default calls writeGotPlt(). ARM and i386 override this to write the address of the ifunc resolver. Differential Revision: https://reviews.llvm.org/D27581 llvm-svn: 289198
* Move Memory.{h,cpp} to lld/Support so that we can use them from COFF.Rui Ueyama2016-12-081-2/+1
| | | | llvm-svn: 289084
* [ELF] ifunc implementation using synthetic sectionsPeter Smith2016-12-081-5/+74
| | | | | | | | | | | | | | | | | This change introduces new synthetic sections IpltSection, IgotPltSection that represent the ifunc entries that would previously have been put in the PltSection and the GotPltSection. The separation makes sure that the R_*_IRELATIVE relocations are placed after the non R_*_IRELATIVE relocations, which permits ifunc resolvers to know that the .got.plt slots will be initialized prior to the resolver being called. A secondary benefit is that for ARM we can move the IgotPltSection and its dynamic relocations to the .got and .rel.dyn as the ARM glibc expects all the R_*_IRELATIVE relocations to be in the .rel.dyn Differential revision: https://reviews.llvm.org/D27406 llvm-svn: 289045
* [ELF] Only binaries should have DT_DEBUG entryPetr Hosek2016-12-071-1/+1
| | | | | | | | The presence of DT_DEBUG entry is unrelated to the existence of entry point. Differential Revision: https://reviews.llvm.org/D27496 llvm-svn: 288877
* Factor out common code to a header.Rui Ueyama2016-12-031-8/+3
| | | | llvm-svn: 288599
* [ELF] - Add support of proccessing of the rest allocatable synthetic ↵George Rimar2016-11-291-0/+4
| | | | | | | | | | | sections from linkerscript. This change continues what was started by D27040 Now all allocatable synthetics should be available from script side. Differential revision: https://reviews.llvm.org/D27131 llvm-svn: 288150
* [ELF][MIPS] Do not change MipsGotSection state in the getPageEntryOffset methodSimon Atanasyan2016-11-291-27/+36
| | | | | | | | | | | | | | The MipsGotSection::getPageEntryOffset calculates index of GOT entry with a "page" address. Previously this method changes the state of MipsGotSection because it modifies PageIndexMap field. That leads to the unpredictable results if getPageEntryOffset called from multiple threads. The patch makes getPageEntryOffset constant. To do so it calculates GOT entry index but does not update PageIndexMap field. Later in the MipsGotSection::writeTo method linker calculates "page" addresses and writes them to the output. llvm-svn: 288129
* [ELF][MIPS] Replace the magic number of GOT header entries by constant. NFCSimon Atanasyan2016-11-291-16/+15
| | | | llvm-svn: 288128
* [ELF][MIPS] Fix calculation of GOT "page address" entries numberSimon Atanasyan2016-11-291-3/+3
| | | | | | | | | | | | | | | | | If output section which referenced by R_MIPS_GOT_PAGE or R_MIPS_GOT16 relocations is small (less that 0x10000 bytes) and occupies two adjacent 0xffff-bytes pages, current formula gives incorrect number of required "page" GOT entries. The problem is that in time of calculation we do not know the section address and so we cannot calculate number of 0xffff-bytes pages exactly. This patch fix the formula. Now it gives a correct number of pages in the worst case when "small" section intersects 0xffff-bytes page boundary. From the other side, sometimes it adds one more redundant GOT entry for each output section. But usually number of output sections referenced by GOT relocations is small. llvm-svn: 288127
* Use relocations to fill statically known got entries.Rafael Espindola2016-11-291-20/+9
| | | | | | | | | | | | | Right now we just remember a SymbolBody for each got entry and duplicate a bit of logic to decide what value, if any, should be written for that SymbolBody. With ARM there will be more complicated values, and it seems better to just use the relocation code to fill the got entries. This makes it clear that each entry is filled by the dynamic linker or by the static linker. llvm-svn: 288107
* Add paralell_for and use it where appropriate.Rui Ueyama2016-11-271-6/+4
| | | | | | | When we iterate over numbers as opposed to iterable elements, parallel_for fits better than parallel_for_each. llvm-svn: 288002
* [ELF] - Add support for access to most of synthetic sections from linkerscript.George Rimar2016-11-251-6/+26
| | | | | | | | | | | | | | | | | | This is important for cases like: .sdata : { *(.got.plt .got) ... } That was not supported before as there was no way to get access to synthetic sections from script. More details on review page. Differential revision: https://reviews.llvm.org/D27040 llvm-svn: 287913
* Use a more explicit type for the sizeof.Rafael Espindola2016-11-241-1/+1
| | | | llvm-svn: 287895
* [ELF] Add terminating sentinel .ARM.exidx table entryPeter Smith2016-11-241-0/+25
| | | | | | | | | | | | | | | | | | | | | The .ARM.exidx table has an entry for each function with the first entry giving the start address of the function, the table is sorted in ascending order of function address. Given a PC value, the unwinder will search the table for the entry that contains the PC value. If the table entry happens to be the last, the range of the addresses that the final unwinding table describes will extend to the end of the address space. To prevent an incorrect address outside the address range of the program matching the last entry we follow ld.bfd's example and add a sentinel EXIDX_CANTUNWIND entry at the end of the table. This gives the final real table entry an upper bound. In addition the llvm libunwind unwinder currently depends on the presence of a sentinel entry (PR31091). Differential revision: https://reviews.llvm.org/D26977 llvm-svn: 287869
* [ELF][MIPS] Fix handling of _gp/_gp_disp/__gnu_local_gp symbolsSimon Atanasyan2016-11-231-4/+8
| | | | | | | | | | | | | | | | | | | | | | | | Offset between beginning of a .got section and _gp symbols used in MIPS GOT relocations calculations. Usually the expression looks like VA + Offset - GP, where VA is the .got section address, Offset - offset of the GOT entry, GP - offset between .got and _gp. Also there two "magic" symbols _gp_disp and __gnu_local_gp which hold the offset mentioned above. These symbols might be referenced by MIPS relocations. Now the linker always defines _gp symbol and uses hardcoded value for its initialization. So offset between .got and _gp is 0x7ff0. The _gp_disp and __gnu_local_gp defined if required and initialized by 0x7ff0. In fact that is not correct because _gp symbol might be defined by a linker script and holds arbitrary value. In that case we need to use this value in relocation calculation and initialize _gp_disp and __gnu_local_gp properly. The patch fixes the problem and completes fixing the bug #30311. https://llvm.org/bugs/show_bug.cgi?id=30311 Differential revision: https://reviews.llvm.org/D27036 llvm-svn: 287832
* Fix this on 32 bit hosts.Rafael Espindola2016-11-231-1/+1
| | | | | | Looks like we have no 32 bit bot that builds with mips support. llvm-svn: 287799
* Re-commit r287727: Use SHA1::hash and MD5::hash functions.Rui Ueyama2016-11-231-8/+2
| | | | | | | r287727 was not a change that broke buildbots; the other change (r287726) that I made to LLVM broke them. llvm-svn: 287788
* Define toString() as a generic function to get a string for error message.Rui Ueyama2016-11-231-4/+4
| | | | | | | | | | | | | | | We have different functions to stringize objects to construct error messages. For InputFile, we have getFilename, and for InputSection, we have getName. You had to memorize them. I think this is the case where the function overloading comes in handy. This patch defines toString() functions that are overloaded for all these types, so that you just call it in error(). Differential Revision: https://reviews.llvm.org/D27030 llvm-svn: 287787
* Revert r287727: Use SHA1::hash and MD5::hash functions.Rui Ueyama2016-11-231-2/+8
| | | | | | It broke buildbots. llvm-svn: 287730
* Use SHA1::hash and MD5::hash functions.Rui Ueyama2016-11-231-8/+2
| | | | llvm-svn: 287727
* Fix memory leak detected by asan.Rui Ueyama2016-11-221-1/+1
| | | | llvm-svn: 287714
* Fix build breakage.Rui Ueyama2016-11-221-7/+6
| | | | | | | We cannot have MipsRldMap class and In<ELFT>::MipsRldMap. Renamed the class. llvm-svn: 287683
* [ELF] Convert .rld_map to input sectionEugene Leviant2016-11-221-2/+21
| | | | | | Differential revision: https://reviews.llvm.org/D26958 llvm-svn: 287675
* Inline small function. NFC.Rui Ueyama2016-11-221-7/+5
| | | | llvm-svn: 287620
* Convert MipsOptionsSection to SyntheticSection.Rui Ueyama2016-11-221-42/+47
| | | | llvm-svn: 287615
* Convert MipsReginfoSection to SyntheticSection.Rui Ueyama2016-11-221-19/+35
| | | | llvm-svn: 287614
* Convert MipsAbiFlagsSection to SyntheticSection.Rui Ueyama2016-11-221-15/+31
| | | | llvm-svn: 287613
* Remove redundant assignment.Rui Ueyama2016-11-221-3/+1
| | | | llvm-svn: 287607
* Convert BuildId a derived class of SyntheticSection.Rui Ueyama2016-11-221-34/+30
| | | | | | | | Some synthetic sections are not derived calsses of SyntehticSection. They are derived directly from InputSection. For consistencly, we should use SyntheticSection. llvm-svn: 287606
* Remove a parameter from getOutputLoc and rename for readability. NFC.Rui Ueyama2016-11-221-6/+5
| | | | llvm-svn: 287605
* Merge BuildId subclasses.Rui Ueyama2016-11-221-69/+54
| | | | | | | We had five different BuildId subclasses for five different types of build-ids. They can simply be merged to a single class. llvm-svn: 287603
* Move a function definition to SyntheticSections.cpp.Rui Ueyama2016-11-211-0/+5
| | | | | | This should have been moved along with r287554. llvm-svn: 287564
* [ELF] Convert Version*** sections to input sectionsEugene Leviant2016-11-211-7/+189
| | | | | | Differential revision: https://reviews.llvm.org/D26918 llvm-svn: 287554
* [ELF] Convert EhFrameHeader to input sectionEugene Leviant2016-11-211-0/+47
| | | | | | Differential revision: https://reviews.llvm.org/D26906 llvm-svn: 287549
OpenPOWER on IntegriCloud