summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter/ELF/OutputELFWriter.h
Commit message (Collapse)AuthorAgeFilesLines
* Remove the old ELF linker.Rafael Espindola2016-02-281-153/+0
| | | | | | I think it is clear by now that the new linker is viable. llvm-svn: 262158
* [ELF] Define __start_XXX/__stop_XXX symbols where XXX is a section nameSimon Atanasyan2015-07-031-1/+2
| | | | | | | | | | | | | | This is GNU ELF linker extension used particularly by LibC code. If input object files contain section named XXX, and the XXX is a valid C identifier, and there are undefined or weak symbols __start_XXX/__stop_XXX, linker should define __start_XXX/__stop_XXX symbols point to the begin/end of the XXX section correspondingly. For example, without support of this extension statically linked executables for X86_64 and Mips (maybe other) targets do not flush IO buffers at the end of executing. llvm-svn: 241341
* [ELF] Move start/end atom method assignment to OutputELFWriter. NFCDenis Protivensky2015-05-211-0/+3
| | | | llvm-svn: 237886
* ELF: Split OutputELFWriter.h to OutputELFWriter.{h,cpp}.Rui Ueyama2015-04-141-448/+4
| | | | | | The size of AArch64TargetHandler.cpp.o is now 4.5MB. llvm-svn: 234916
* [ELF] Set `addAbsoluteAtom` and `addUndefinedAtom` functions return type to voidSimon Atanasyan2015-04-071-1/+1
| | | | | | | We do not use values returned by these functions anywhere. So let's return nothing. llvm-svn: 234358
* [ELF] Simplify adding default atomsSimon Atanasyan2015-04-071-14/+6
| | | | | | | | | | | | | | | | | | | | | Now 'writer' creates an instance of `RuntimeFile` in the constructor, then populates the file in the virtual function `addDefaultAtoms`, then pass owning of this file to the caller of virtual function `createImplicitFiles`. First, we do not need to keep an instance of `RuntimeFile` so long. It is enough to create the file, right after that populate it and pass the owning. Second, relationship between `createImplicitFiles` and `addDefaultAtoms` is complicated. The `createImplicitFiles` might call `addDefaultAtoms`, overridden version of `addDefaultAtoms` might call base class `addDefaultAtoms`, and overridden version of `createImplicitFiles` might call base class `createImplicitFiles` as well as `addDefaultAtoms`. The patch solves both problems above. It creates and populates runtime files right in the createImplicitFiles(), removes `addDefaultAtoms` at all and does not keep references to runtime files in class fields. llvm-svn: 234347
* [ELF] Remove redundant const_castSimon Atanasyan2015-04-071-3/+2
| | | | | | No functional changes. llvm-svn: 234293
* [GNU] Implement --enable-new-dtags/--disable-new-dtagsDavide Italiano2015-04-061-1/+1
| | | | | | | PR: 23036 Differential Revision: http://reviews.llvm.org/D8836 llvm-svn: 234240
* Replace the `createImplicitFiles` method return type with `void`Simon Atanasyan2015-04-061-3/+2
| | | | | | | All instances of the `createImplicitFiles` always return `true` and this return value is used nowhere. llvm-svn: 234205
* Strip .strtab and .symtab when --strip-all is used.Davide Italiano2015-04-051-9/+16
| | | | | | | | | | This matches other linkers behaviour. Moreover, there's really no need to keep them around. Reported by: Rafael Avila de Espindola PR: 22890 llvm-svn: 234130
* [ELF] Delete empty TargetLayout class and rename DefaultLayout to TargetLayoutSimon Atanasyan2015-04-031-12/+10
| | | | | | No functional changes. llvm-svn: 234052
* ELF: Remove TargetHandlerBase by merging it with TargetHandler.Rui Ueyama2015-04-011-2/+2
| | | | | | | | | | | | | | | | | | | In r233772, I removed an empty class, DefaultTargetHandler, from the class hierarchy by merging the class with TargetHandler. I then found that TargetHandler and its base class, TargetHandlerBase, are also almost the same. We need to go deeper. In this patch, I merged TargetHandlerBase with TargetHandler. The only difference between them is the existence (or absense) of a pure virtual function registerRelocationName(). I added that function to the (new) TargetHandler. One more thing is that TargetHandler was templated for no reason. I made it non-templated class. llvm-svn: 233773
* ELF: Make findAbsoluteAtom return AtomLayout* instead of an iterator.Rui Ueyama2015-03-311-2/+3
| | | | | | | | | | | All calls of findAbsoluteAtoms seem a bit awkward because of the type of the function. It semantically returns a pointer to an AtomLayout or nothing, so I made the function return AtomLayout*. In this patch, I also expanded some "auto"s because their actual type were not obvious in their contexts. llvm-svn: 233769
* ELF: make scopes of error code varaibles narrower.Rui Ueyama2015-03-271-11/+5
| | | | llvm-svn: 233450
* ELF: Simplify SymbolFile.Rui Ueyama2015-03-271-12/+2
| | | | llvm-svn: 233449
* Rename ELFLinkingContext instances "ctx" intead of "context".Rui Ueyama2015-03-271-44/+42
| | | | llvm-svn: 233344
* [ELF] Use parallel_for_each for writing.Shankar Easwaran2015-03-171-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This changes improves performance of lld, when self-hosting lld, when compared with the bfd linker. BFD linker on average takes 8 seconds in elapsed time. lld takes 3 seconds elapased time average. Without this change, lld takes ~5 seconds average. The runtime comparisons were done on a release build and measured by running linking thrice. lld self-host without the change ---------------------------------- real 0m3.196s user 0m4.580s sys 0m0.832s lld self-host with lld ----------------------- user 0m3.024s user 0m3.252s sys 0m0.796s time taken to build lld with bfd -------------------------------- real 0m8.419s user 0m7.748s sys 0m0.632s llvm-svn: 232460
* [LinkerScript] Handle symbols defined in linker scriptsRafael Auler2015-03-161-13/+36
| | | | | | | | | | Puts symbols defined in linker script expressions in a runtime file that is added as input to the resolver, making the input object files see symbols defined in linker scripts. http://reviews.llvm.org/D8263 llvm-svn: 232409
* Revert "[ELF] Change few static functions."Shankar Easwaran2015-03-141-2/+2
| | | | | | | | This reverts commit r232253. Fix comments from dblaikie. Since these functions dont access member state, its ok to be static. llvm-svn: 232271
* [ELF] Ability to resolve undefined symbols lazilyDenis Protivensky2015-03-141-0/+69
| | | | | | | | | Handle resolution of symbols coming from linked object files lazily. Add implementation of handling _GLOBAL_OFFSET_TABLE_ and __exidx_start/_end symbols for ARM platform. Differential Revision: http://reviews.llvm.org/D8159 llvm-svn: 232261
* [ELF] Change few static functions.Shankar Easwaran2015-03-141-2/+2
| | | | | | Functions hasOutputSegment/maybeGetSOName doesnot need not be static. llvm-svn: 232253
* Use template aliases.Rui Ueyama2015-03-101-22/+22
| | | | | | We dropped Visual Studio 2012 support, so we can use template aliases. llvm-svn: 231756
* [ELF] Add section group/COMDAT support.Shankar Easwaran2015-02-231-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | SHF_GROUP: Group Member Sections ---------------------------------- A section which is part of a group, and is to be retained or discarded with the group as a whole, is identified by a new section header attribute: SHF_GROUP This section is a member (perhaps the only one) of a group of sections, and the linker should retain or discard all or none of the members. This section must be referenced in a SHT_GROUP section. This attribute flag may be set in any section header, and no other modification or indication is made in the grouped sections. All additional information is contained in the associated SHT_GROUP section. SHT_GROUP: Section Group Definition ------------------------------------- Represents a group section. The section group's sh_link field identifies a symbol table section, and its sh_info field the index of a symbol in that section. The name of that symbol is treated as the identifier of the section group. More information: https://mentorembedded.github.io/cxx-abi/abi/prop-72-comdat.html Added a lot of extensive tests, that tests functionality. llvm-svn: 230195
* [ELF] Implement --strip-all/-sDavide Italiano2015-02-081-1/+3
| | | | | | | Differential Revision: D7489 Reviewed by: shankarke llvm-svn: 228533
* Fix five of the shared library build targetsGreg Fitzgerald2015-01-211-1/+1
| | | | | | | | | | | | | | | | | | Before this patch there was a cyclic dependency between lldCore and lldReaderWriter. Only lldConfig could be built as a shared library. * Moved Reader and Writer base classes into lldCore. * The following shared libraries can now be built: lldCore lldYAML lldNative lldPasses lldReaderWriter Differential Revision: http://reviews.llvm.org/D7105 From: Greg Fitzgerald <garious@gmail.com> llvm-svn: 226732
* [ELF] Add --as-needed.Rui Ueyama2015-01-161-0/+20
| | | | | | | | | | | | The previous default behavior of LLD is --as-needed. LLD linked against a DSO only if the DSO file was actually used to link an executable (i.e. at least one symbol was resolved using the shared library file.) In this patch I added a boolean flag to FileNode for --as-needed. I also added an accessor to DSO name to shared library file class. llvm-svn: 226274
* [ELF] Adjust ELF header entry symbol value if this symbol is microMIPS encodedSimon Atanasyan2014-12-041-3/+4
| | | | | | | To find an AtomLayout object for the given symbol I replace the `Layout::findAtomAddrByName` method by `Layout::findAtomLayoutByName` method. llvm-svn: 223359
* [ELF] Create input and output section namesShankar Easwaran2014-11-301-1/+3
| | | | | | No change in functionality. llvm-svn: 222973
* [ELF] Rename MergedSection to OutputSection.Shankar Easwaran2014-11-301-10/+10
| | | | | | No change in functionality. llvm-svn: 222972
* Revert "[ELF] Rename MergedSection to OutputSection."Shankar Easwaran2014-11-191-10/+10
| | | | | | | | | This reverts commit r222310. Not sure which commit is the cause of the failure on the darwin bot. Will need to revert my changes and commit one change at a time. llvm-svn: 222330
* Revert "[ELF] Create input and output section names"Shankar Easwaran2014-11-191-3/+1
| | | | | | | | This reverts commit r222311. Reverting because of failure in the darwin bot. llvm-svn: 222329
* [ELF] Create input and output section namesShankar Easwaran2014-11-191-1/+3
| | | | | | No change in functionality. llvm-svn: 222311
* [ELF] Rename MergedSection to OutputSection.Shankar Easwaran2014-11-191-10/+10
| | | | | | No change in functionality. llvm-svn: 222310
* [ELF] Add CodeModel attribute to the DefinedAtom classSimon Atanasyan2014-11-131-2/+11
| | | | | | | | | | | | | | | | | | | | | | MIPS ELF symbols might contain some additional MIPS-specific flags in the st_other field besides visibility ones. These flags indicate code properties like microMIPS / MIPS16 encoding, position independent code etc. We need to transfer the flags from input objects to the output linked file to write them into the symbol table, adjust symbols addresses etc. I add new attribute CodeModel to the DefinedAtom class to hold target specific flag and to get over YAML/Native format conversion barrier. Other architectures/targets can extend CodeModel enumeration by their own flags. MIPS specific part of this patch adds support for STO_MIPS_MICROMIPS flag. This flag marks microMIPS symbols. Such symbol should: a) Has STO_MIPS_MICROMIPS in the corresponding .symtab record. b) Has adjusted (odd) address in the corresponding .symtab and .dynsym records. llvm-svn: 221864
* [ELF] Remove is64bits() and isLittlEndian().Shankar Easwaran2014-11-071-5/+5
| | | | | | | | | | ELFLinkingContext had these two functions, which is really not needed since the Writer uses a llvm::object template composed of Endianness, Alignment, Is32bit/64bit. We could just use that and not duplicate functionality. No Change In Functionality. llvm-svn: 221523
* [ELF] Fix program headers.Shankar Easwaran2014-11-041-2/+1
| | | | | | | | | The ELF writer creates a invalid binary for few cases with large filesize and memory size for segments. This patch addresses the functionality and updates the test. This patch also cleans up parts of the ELF writer for future enhancements to support Linker scripts. llvm-svn: 221233
* [ELF] Add Readers for all the ELF subtargets.Shankar Easwaran2014-10-181-2/+0
| | | | | | | | | This would permit the ELF reader to check the architecture that is being selected by the linking process. This patch also sorts the include files according to LLVM conventions. llvm-svn: 220129
* Reapply [ELF] Only mark as DT_NEEDED libs that are strictly necessary (r219353)Rafael Auler2014-10-091-2/+5
| | | | | | | | | | | | | | | | | | | | When committed in r219353, this patch originally caused problems because it was not tested in debug build. In such scenarios, Driver.cpp adds two additional passes. These passes serialize all atoms via YAML and reads it back. Since the patch changed ObjectAtom to hold a new reference, the serialization was removing the extra data. This commit implements r219853 in another way, similar to the original MIPS way, by using a StringSet that holds the names of all copied atoms instead of directly holding a reference to the copied atom. In this way, this commit is simpler and eliminate the necessity of changing the DefinedAtom hierarchy to hold a new data. Reviewers: shankarke http://reviews.llvm.org/D5713 llvm-svn: 219449
* Revert "[ELF] Only mark as DT_NEEDED libs that are strictly necessary"Rui Ueyama2014-10-091-5/+2
| | | | | | This reverts commit r219353 because that seems to break buildbots. llvm-svn: 219369
* [ELF] Only mark as DT_NEEDED libs that are strictly necessaryRafael Auler2014-10-081-2/+5
| | | | | | | | | | | | | | | | | | | | | Enhances the creation of an ELF dynamic executable by avoiding recording unnecessary shared libraries as NEEDED to load a program. To do this, we must keep track of not only symbols that were referenced but also of COPY relocations, which steal the symbol from a shared library but does not store from which lib this symbol came from. To fix this, this commit changes ObjectSymbol to store the original library from which this symbol came. With this information, we are able to build a list of the exact shared libraries that must be marked as DT_NEEDED, instead of blindly marking all shared libraries as needed. This logic originally came from the MIPS backend with some adaptation. Reviewers: atanasyan, shankar.easwaran http://reviews.llvm.org/D5574 llvm-svn: 219353
* [ELF] Implement --export-dynamic/-ERafael Auler2014-10-081-9/+0
| | | | | | | | | | | | | | | | | When creating a dynamic executable and receiving the -E flag, the linker should export all globally visible symbols in its dynamic symbol table. This commit also moves the logic that exports symbols in the dynamic symbol table from OutputELFWriter to the ExecutableWriter class. It is not correct to leave this at OutputELFWriter because DynamicLibraryWriter, another subclass of OutputELFWriter, already exports all symbols, meaning we can potentially end up with duplicated symbols in the dynamic symbol table when creating shared libs. Reviewers: shankarke http://reviews.llvm.org/D5585 llvm-svn: 219334
* [ELF] Never mark the dynamic linker as DT_NEEDEDRafael Auler2014-10-021-0/+3
| | | | | | | | | | | | This patch adds logic to avoid putting the dynamic linker library (ld.so) as a DT_NEEDED entry in the dynamic table. It should only appear in PT_INTERP. This patch fixes SPEC programs 433, 445, 450, 453, 456, 462 when running on Ubuntu Linux x86_64 and when linking SPEC programs with LLD and glibc 2.19. http://reviews.llvm.org/D5573 llvm-svn: 218847
* [lld] [ELF] Support for general dynamic TLS relocations on X86_64Rafael Auler2014-09-291-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch adds support for the general dynamic TLS access model for X86_64 (see www.akkadia.org/drepper/tls.pdf). To properly support TLS, the patch also changes the __tls_get_addr atom to be a shared library atom instead of a regularly defined atom (the previous lld approach). This closely models the reality of a function that will be resolved at runtime by the dynamic linker and loader itself (ld.so). I was tempted to force LLD to link against ld.so itself to resolve these symbols, but since GNU ld does not need the ld.so library to resolve this symbol, I decided to mimic its behavior and keep hardwired a definition of __tls_get_addr in the lld code. This patch also moves some important logic that previously was only available to the MIPS lld backend to be used to all ELF backends. This logic, which now lives in the DefaultLayout class, will monitor which external (shared lib) symbols are really imported by the current module and will only populate the dynamic symbol table with used symbols, as opposed to the previous approach of dumping all shared lib symbols in the dynamic symbol table. This is important to this patch to avoid __tls_get_addr from getting injected into all dynamic symbol tables. By solving the previous problem of always adding __tls_get_addr, now the produced symbol tables are slightly smaller. But this impacted several tests that relied on hardwired/predefined sizes of the symbol table, requiring this patch to update such tests. Test Plan: Added a LIT test case that exercises a simple use case of TLS variable in a shared library. Reviewers: ruiu, rafael, Bigcheese, shankarke Reviewed By: Bigcheese, shankarke Subscribers: emaste, shankarke, joerg, kledzik, mcrosier, llvm-commits Projects: #lld Differential Revision: http://reviews.llvm.org/D5505 llvm-svn: 218633
* Re-commit r218259.Rui Ueyama2014-09-221-1/+1
| | | | llvm-svn: 218272
* Revert "[ELF] Fix linking when a regular object defines a symbol that is ↵Rui Ueyama2014-09-221-1/+1
| | | | | | | | | used in a DSO" This commit reverts r218259 because it needed to be checked in with a few binary files for the test. llvm-svn: 218262
* [ELF] Fix linking when a regular object defines a symbol that is used in a DSORui Ueyama2014-09-221-1/+1
| | | | | | | | | | | | | | | | | | Patch from Rafael Auler! When a shared lib has an undefined symbol that is defined in a regular object (the program), the final executable must export this symbol in the dynamic symbol table. However, in the current logic, lld only puts the symbol in the dynamic symbol table if the symbol is weak. This patch fixes lld to put the symbol in the dynamic symbol table regardless if it is weak or not. This caused a problem in FreeBSD10, whose programs link against a crt1.o that defines the symbol __progname, which is, in turn, undefined in libc.so.7 and will only be resolved in runtime. http://reviews.llvm.org/D5424 llvm-svn: 218259
* [ELF] Export strong defined symbol if it coalesces away a weak symbolSimon Atanasyan2014-09-081-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | defined in a shared library. Now LLD does not export a strong defined symbol if it coalesces away a weak symbol defined in a shared library. This bug affects all ELF architectures and leads to segfault: % cat foo.c extern int __attribute__((weak)) flag; int foo() { return flag; } % cat main.c int flag = 1; int foo(); int main() { return foo() == 1 ? 0 : -1; } % clang -c -fPIC foo.c main.c % lld -flavor gnu -target x86_64 -shared -o libfoo.so ... foo.o % lld -flavor gnu -target x86_64 -o a.out ... main.o libfoo.so % ./a.out Segmentation fault The problem is caused by the fact that we lose all information about coalesced symbols after the `Resolver::resolve()` method is finished. The patch solves the problem by overriding the `LinkingContext::notifySymbolTableCoalesce()` method and saving names of coalesced symbols. Later in the `buildDynamicSymbolTable()` routine we use this information to export these symbols. llvm-svn: 217363
* [ELF] Add two new virtual functions to the `OutputELFWriter` class to controlSimon Atanasyan2014-06-251-2/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | dynamic symbol table populating and DT_NEEDED tag creation. The `isDynSymEntryRequired` function returns true if the specified shared library atom requires a dynamic symbol table entry. The `isNeededTagRequired` function returns true if we need to create DT_NEEDED tag for the shared library defined specified shared atom. By default the both functions return true. So there is no functional changes for all targets except MIPS. Probably we need to spread the same modifications on other ELF targets but I want to implement and fully tested complete set of changes for MIPS target first. For MIPS we create a dynamic symbol table entry for a shared library atom iif this atom is referenced by a regular defined atom. For example, if library L1 defines symbol T1, library L2 defines symbol T2 and uses symbol T1 and executable file E1 uses symbol T2 but does not use symbol T1 we create an entry in the E1 dynamic symbol table for symbol T2 and do not create an entry for T1. The patch creates DT_NEEDED tags for shared libraries contain shared library atoms which a) referenced by regular defined atoms; b) have corresponding copy dynamic relocations (R_MIPS_COPY). Now the patch does not take in account --as-needed / --no-as-needed command line options. So it is too restrictive and create DT_NEEDED tags for really needed shared libraries only. I plan to fix that by subsequent patches. llvm-svn: 211674
* More prefixing of error_code.Rafael Espindola2014-06-121-14/+15
| | | | llvm-svn: 210831
* [ELF] Fix typo in the type name of the range-based loop item.Simon Atanasyan2014-06-101-1/+1
| | | | | | No functional changes. llvm-svn: 210531
OpenPOWER on IntegriCloud