summaryrefslogtreecommitdiffstats
path: root/lld/ELF/Symbols.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Add a comment.Sean Silva2017-02-281-0/+11
| | | | | | | | | | | | | | | Naively it seemed at first like getVA had the responsibility of adding the addend, and getSymVA had the responsibility of getting the symbol VA. So it was not obvious to me at first why getVA passes Addend to getSymVA. In fact, it passes it as a mutable reference. It turns out that it only matters for SHF_MERGE sections, and in particular only for STT_SECTION symbols that are used as a hack for reducing the number of local symbols (e.g. to avoid a local symbol for each string in the string table). llvm-svn: 296448
* Move SymbolTableSection::getOutputSection to SymbolBody::getOutputSection.Rui Ueyama2017-02-281-0/+34
| | | | | | | | | That function doesn't use any member of SymbolTableSection, so I couldn't see a reason to make it a member of that class. The function takes a SymbolBody, so it is more natural to make it a member of SymbolBody. llvm-svn: 296433
* Remove useless template so that Out<ELFT> becomes just Out.Rui Ueyama2017-02-271-2/+2
| | | | llvm-svn: 296307
* De-template SharedSymbol.Rui Ueyama2017-02-261-8/+19
| | | | | | Differential Revision: https://reviews.llvm.org/D30351 llvm-svn: 296303
* Merge OutputSectionBase and OutputSection. NFC.Rafael Espindola2017-02-241-2/+2
| | | | | | | Now that all special sections are SyntheticSections, we only need one OutputSection class. llvm-svn: 296127
* Make InputSection a class. NFC.Rafael Espindola2017-02-231-1/+1
| | | | | | | | | With the current design an InputSection is basically anything that goes directly in a OutputSection. That includes plain input section but also synthetic sections, so this should probably not be a template. llvm-svn: 295993
* Convert InputSectionBase to a class.Rafael Espindola2017-02-231-4/+5
| | | | | | | Removing this template is not a big win by itself, but opens the way for removing more templates. llvm-svn: 295923
* Do not use errs() or outs() directly. Instead use message(), log() or error()Rui Ueyama2017-02-211-6/+6
| | | | | | | | | LLD is a multi-threaded program. errs() or outs() are not guaranteed to be thread-safe (they are actually not). LLD's message(), log() or error() are thread-safe. We should use them. llvm-svn: 295787
* Removes a trivial accessor.Rui Ueyama2017-02-161-11/+2
| | | | llvm-svn: 295288
* Do not overload a one-bit variable, NeedsCopyOrPltAddr.Rui Ueyama2017-02-161-10/+10
| | | | | | | | | This patch removes NeedsCopyOrPltAddr and instead add two variables, NeedsCopy and NeedsPltAddr. This uses one more bit in Symbol class, but the actual size doesn't increase because we had unused bits. This should improve code readability. llvm-svn: 295287
* Addends should always be signed.Rafael Espindola2017-02-161-7/+6
| | | | | | | | | | In the target dependent code we already always return a int64_t. In the target independent code we carefully use uintX_t, which has the same result given 2 complement rules. This just simplifies the code to use int64_t everywhere. llvm-svn: 295263
* [ELF] Use synthetic section to hold copy relocationPeter Smith2017-02-091-4/+6
| | | | | | | | | | | | | | When we need a copy relocation we create a synthetic SHT_NOBITS section that contains the right amount of ZI and assign it to either .bss or .rel.ro.bss as appropriate. This allows the dynamic relocation to be placed on the InputSection, removing the last case where a dynamic relocation is stored as an offset from the OutputSection. This has the side effect that we can run assignOffsets() after scanRelocs() without losing the additional ZI needed for the copy relocations. Differential Revision: https://reviews.llvm.org/D29637 llvm-svn: 294577
* Replace MergeOutputSection with a synthetic section.Rafael Espindola2017-02-031-1/+2
| | | | | | | | | | | | | | With a synthetic merge section we can have, for example, a single .rodata section with stings, fixed sized constants and non merge constants. I can be simplified further by not setting Entsize, but that is probably better done is a followup patch. This should allow some cleanup in the linker script code now that every output section command maps to just one output section. llvm-svn: 294005
* [ELF] Use SyntheticSections for ThunksPeter Smith2017-02-011-36/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | Thunks are now implemented by redirecting the relocation to the symbol S, to a symbol TS in a Thunk. The Thunk will transfer control to S. This has the following implications: - All the side-effects of Thunks happen within createThunks() - Thunks are no longer stored in InputSections and Symbols no longer need to hold a pointer to a Thunk - The synthetic Thunk sections need to be merged into OutputSections This implementation is almost a direct conversion of the existing Thunks with the following exceptions: - Mips LA25 Thunks are placed before the InputSection that defines the symbol that needs a Thunk. - All ARM Thunks are placed at the end of the OutputSection of the first caller to the Thunk. Range extension Thunks are not supported yet so it is optimistically assumed that all Thunks can be reused. This is a recommit of r293283 with a fixed comparison predicate as std::merge requires a strict weak ordering. Differential revision: https://reviews.llvm.org/D29327 llvm-svn: 293757
* Revert "[ELF][ARM] Use SyntheticSections for Thunks"Rui Ueyama2017-01-281-2/+36
| | | | | | This reverts commit r293283 because it broke MSVC build. llvm-svn: 293352
* [ELF][ARM] Use SyntheticSections for ThunksPeter Smith2017-01-271-36/+2
| | | | | | | | | | | | | | | | | | | | | | | | Thunks are now implemented by redirecting the relocation to the symbol S, to a symbol TS in a Thunk. The Thunk will transfer control to S. This has the following implications: - All the side-effects of Thunks happen within createThunks() - Thunks are no longer stored in InputSections and Symbols no longer need to hold a pointer to a Thunk - The synthetic Thunk sections need to be merged into OutputSections This implementation is almost a direct conversion of the existing Thunks with the following exceptions: - Mips LA25 Thunks are placed before the InputSection that defines the symbol that needs a Thunk. - All ARM Thunks are placed at the end of the OutputSection of the first caller to the Thunk. Range extension Thunks are not supported yet so it is optimistically assumed that all Thunks can be reused. Differential Revision: https://reviews.llvm.org/D29129 llvm-svn: 293283
* Do not allocate space for common symbols with -rRui Ueyama2017-01-241-0/+2
| | | | | | | | | | | | | | | 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
* Add a isInCurrentDSO helper. NFC.Rafael Espindola2017-01-171-3/+3
| | | | llvm-svn: 292228
* Give priority to linker scripts over preemption.Rafael Espindola2017-01-161-1/+2
| | | | | | | | | | | | LLD exports symbols that are also present in used shared libraries to make sure they are preempted at runtime. That is a reasonable default, but we must allow for it to be overwritten with linker script. If we don't, libraries that expect to be able to hide a c++ delete operator will fail. This should fix the firebird build. llvm-svn: 292146
* Give local binding to VER_NDX_LOCAL symbols.Rafael Espindola2017-01-101-2/+14
| | | | | | | 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-2/+14
| | | | | | | | | | | | | | 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
* Handle versioned undefined symbols.Rafael Espindola2017-01-061-0/+4
| | | | | | | In order to keep symbol lookup a simple name lookup this patch adds versioned symbols with an explicit @ to the symbol table. llvm-svn: 291293
* Merge elf::toString and coff::toString.Rui Ueyama2017-01-061-1/+1
| | | | | | The two overloaded functions hid each other. This patch merges them. llvm-svn: 291222
* [ELF] Add support for thunks to undefined non-weak symbolsPeter Smith2017-01-041-2/+10
| | | | | | | | | | | | In a shared library an undefined symbol is implicitly imported. If the symbol is called as a function a PLT entry is generated for it. When the caller is a Thumb b.w a thunk to the PLT entry is needed as all PLT entries are in ARM state. This change allows undefined symbols to have thunks in the same way that shared symbols may have thunks. llvm-svn: 290951
* De-template DefinedSynthetic.Rui Ueyama2016-12-211-14/+2
| | | | | | | | 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
* Detemplate PhdrEntry. NFC.Rafael Espindola2016-12-191-0/+1
| | | | llvm-svn: 290115
* Rename this variable.Sean Silva2016-12-151-4/+4
| | | | | | | | | | `SC` didn't make much sense. We don't seem to have a clear convention, but `IS` sounds good here because it emphasizes that it is an input section (this is one place in the code where we are dealing with both input sections and output sections at the same time so that extra emphasis makes it a bit clearer). llvm-svn: 289748
* [ELF] ifunc implementation using synthetic sectionsPeter Smith2016-12-081-2/+6
| | | | | | | | | | | | | | | | | 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
* Make demangle() return None instead of "" if a given string is not a mangled ↵Rui Ueyama2016-12-071-1/+2
| | | | | | symbol. llvm-svn: 288993
* Include object file name to an error message.Rui Ueyama2016-12-051-1/+1
| | | | llvm-svn: 288686
* Introduce StringRefZ class to represent null-terminated strings.Rui Ueyama2016-11-291-32/+16
| | | | | | | | | | | | | | StringRefZ is a class to represent a null-terminated string. String length is computed lazily, so it's more efficient than StringRef to represent strings in string table. The motivation of defining this new class is to merge functions that only differ in string types; we have many constructors that takes `const char *` or `StringRef`. With StringRefZ, we can merge them. Differential Revision: https://reviews.llvm.org/D27037 llvm-svn: 288172
* Define toString(const SymbolBody &) and remove maybeDemangle instead.Rui Ueyama2016-11-241-0/+8
| | | | | | Differential Revision: https://reviews.llvm.org/D27065 llvm-svn: 287899
* Define toString() as a generic function to get a string for error message.Rui Ueyama2016-11-231-2/+2
| | | | | | | | | | | | | | | 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
* Parse symbol versions in scanVersionScript() instead of insert().Rui Ueyama2016-11-231-0/+35
| | | | | | | | | | | | | | | | There are two ways to set symbol versions. One way is to use symbol definition file, and the other is to embed version names to symbol names. In the latter way, symbol name is in the form of `foo@version1` where `foo` is a real name and `version1` is a version. We were parsing symbol names in insert(). That seems unnecessarily too early. We can do it later after we resolve all symbols. Doing it lazily is a good thing because it makes code easier to read (because now we have a separate pass to parse symbol names). Also it could slightly improve performance because if two identical symbols have versions, we now parse them only once. llvm-svn: 287741
* Allow calling getName() on local symbols.Rui Ueyama2016-11-231-18/+11
| | | | | | | | | Previously, we stored offsets in string tables to symbols, so you needed to pass a string table to get a symbol name. This patch stores const char pointers instead to eliminate the need to pass a string table. llvm-svn: 287737
* [ELF] Convert PltSection to input sectionEugene Leviant2016-11-181-1/+1
| | | | | | Differential revision: https://reviews.llvm.org/D26842 llvm-svn: 287346
* [ELF] Add Section() to expression objectEugene Leviant2016-11-161-1/+1
| | | | | | | | | This allows making symbols containing ADDR(section) synthetic, and defining synthetic symbols outside SECTIONS block. Differential revision: https://reviews.llvm.org/D25441 llvm-svn: 287090
* [ELF] Convert .got section to input sectionEugene Leviant2016-11-111-1/+1
| | | | | | Differential revision: https://reviews.llvm.org/D26498 llvm-svn: 286580
* [ELF] Convert .got.plt section to input sectionEugene Leviant2016-11-101-1/+1
| | | | | | Differential revision: https://reviews.llvm.org/D26349 llvm-svn: 286443
* [ELF] - Implemented --symbol-ordering-file option.George Rimar2016-11-101-0/+8
| | | | | | | | | | | | | | | | | | | | | | | Patch allows to pass a symbols file to linker. LLD will map symbols to sections and sort sections in output according to symbol ordering file. That can help to reduce the startup time and/or amount of pagefaults during startup. Also, interesting benchmark result was produced by Rafael Espíndola. After applying the symbols file for clang he timed compiling X86MCTargetDesc.ii to an object file. The page faults went from just 56,988 to 56,946 since most faults are not in the binary. Running time went from 4.403053515 to 4.178112244. The speedup seems to be because of better cache locality. Differential revision: https://reviews.llvm.org/D26130 llvm-svn: 286440
* Make OutputSectionBase a class instead of class template.Rafael Espindola2016-11-091-2/+2
| | | | | | | | The disadvantage is that we use uint64_t instad of uint32_t for some value in 32 bit files. The advantage is a substantially simpler code, faster builds and less code duplication. llvm-svn: 286414
* Split Header into individual fields.Rafael Espindola2016-11-091-8/+8
| | | | | | | | | This is similar to what was done for InputSection. With this the various fields are stored in host order and only converted to target order when writing. llvm-svn: 286327
* Rewrite CommonInputSection as a synthetic input section.Rui Ueyama2016-11-051-2/+2
| | | | | | | | | | | | A CommonInputSection is a section containing all common symbols. That was an input section but was abstracted in a different way than the synthetic input sections because it was written before the synthetic input section was invented. This patch rewrites CommonInputSection as a synthetic input section so that it behaves better with other sections. llvm-svn: 286053
* Consolidate BumpPtrAllocators.Rui Ueyama2016-10-281-8/+7
| | | | | | | | | | | Previously, we have a lot of BumpPtrAllocators, but all these allocators virtually have the same lifetime because they are not freed until the linker finishes its job. This patch aggregates them into a single allocator. Differential revision: https://reviews.llvm.org/D26042 llvm-svn: 285452
* Reduce the number of allocators.Rafael Espindola2016-10-261-7/+8
| | | | | | | | | | We used to have one allocator per file, which reduces the advantage of using an allocator in the first place. This is a small speed up is most cases. The largest speedup was in 1.014X in chromium no-gc. The largest slowdown was scylla at 1.003X. llvm-svn: 285205
* Read section headers upfront.Rafael Espindola2016-10-261-2/+2
| | | | | | | | | | | | | | | | | | Instead of storing a pointer, store the members we need. The reason for doing this is that it makes it far easier to create synthetic sections. It also avoids reading data from files multiple times., which might help with cross endian linking and host architectures with slow unaligned access. There are obvious compacting opportunities, but this already has mixed results even on native x86_64 linking. There is also the possibility of better refactoring the code for handling common symbols, but this already shows that a custom class is not necessary. llvm-svn: 285148
* [ELF][MIPS] Put local GOT entries accessed via a 16-bit index firstSimon Atanasyan2016-10-211-4/+4
| | | | | | | | | | | | | | | | | | | | | | Some MIPS relocations used to access GOT entries are able to manipulate 16-bit index. The other ones like R_MIPS_CALL_HI16/LO16 can handle 32-bit indexes. 16-bit relocations are generated by default. The 32-bit relocations are generated by -mxgot flag passed to compiler. Usually these relocation are not mixed in the same code but files like crt*.o contain 16-bit relocations so even if all "user's" code compiled with -mxgot flag a few 16-bit relocations might come to the linking phase. Now LLD does not differentiate local GOT entries accessed via a 16-bit and 32-bit indexes. That might lead to relocation's overflow if 16-bit entries are allocated to far from the beginning of the GOT. The patch introduces new "part" of MIPS GOT dedicated to the local GOT entries accessed by 32-bit relocations. That allows to put local GOT entries accessed via a 16-bit index first and escape relocation's overflow. Differential revision: https://reviews.llvm.org/D25833 llvm-svn: 284809
* [ThinLTO] Avoid archive member collisions.Davide Italiano2016-10-121-3/+3
| | | | | | | | This fixes PR30665. Differential Revision: https://reviews.llvm.org/D25495 llvm-svn: 284034
* Alternative fix for reloc tareting discarded sectionEugene Leviant2016-10-121-11/+0
| | | | | | | | | | | | r283984 introduced a problem of too many warning messages being shown when -ffunction-sections and -fdata-sections were used in conjunction with --gc-sections linker flag and debugging information present. This happens because lot of relocations from .debug_line section may become invalid in such case. The newer fix doesn't show any warning message but zeroes OutSec pointer in createInputSectionList() to avoid crash, when relocations are written llvm-svn: 284010
* Don't crash if reloc targets discarded sectionEugene Leviant2016-10-121-0/+12
| | | | | | Differential revision: https://reviews.llvm.org/D25433 llvm-svn: 283984
OpenPOWER on IntegriCloud