Commit Graph

261 Commits

Author SHA1 Message Date
Davide Italiano bcdd6c60a0 [ThinLTO] Avoid archive member collisions.
This fixes PR30665.

Differential Revision:  https://reviews.llvm.org/D25495

llvm-svn: 284034
2016-10-12 19:35:54 +00:00
George Rimar 27e651d4f6 Recommit r283733 "[ELF] - Do not crash if common symbol alignment set to value greater than UINT32_MAX.
With fix: commit changes from InputFiles.cpp too.

Original commit message:
We have following code in lld, that truncates the alignment value to 32 bit. Big alignment in this case
may give result 0 and crash later.

template <class ELFT>
CommonInputSection<ELFT>::CommonInputSection(std::vector<DefinedCommon *> Syms)
    : InputSection<ELFT>(nullptr, &Hdr, "") {
....
  for (DefinedCommon *Sym : Syms) {
    this->Alignment = std::max<uintX_t>(this->Alignment, Sym->Alignment);
...
  }
}

Patch fixes the issue.

Differential revision: https://reviews.llvm.org/D25235

llvm-svn: 283738
2016-10-10 10:31:03 +00:00
Peter Smith bafd3c40e2 [ELF][ARM] Fix formatting mistake, removed extra space before ) NFC.
llvm-svn: 283735
2016-10-10 10:18:58 +00:00
Peter Smith 0760605ac5 [ELF][ARM] Garbage collection support for .ARM.exidx sections
.ARM.exidx sections have a reverse dependency on the section they have
a SHF_LINK_ORDER dependency on. In other words a .ARM.exidx section is
live only if the executable section it describes is live. We implement
this with a reverse dependency field in InputSection.

Adding the dependency to InputSection is the simplest implementation
but it could be moved out to a separate map if it were found to decrease
performance for non ARM targets.

Differential revision: https://reviews.llvm.org/D25234

llvm-svn: 283734
2016-10-10 10:10:27 +00:00
George Rimar 9397cf953c [ELF] - Fixed assert fail when symbol table has zero sh_info value.
When sh_info of sumbol table value was set to zero, lld was asserting.

Patch fixes the issue.

Differential revision: https://reviews.llvm.org/D25016

llvm-svn: 283562
2016-10-07 15:16:27 +00:00
George Rimar 53cf2a8112 [ELF] - Do not crash on invalid size of dynamic section.
Previously if sh_size of dynamic section was broken,
lld may crash. Or even may not crash if used 32 bits host.
(then value may be truncated to 32 bits when doing pointer arithmetic 
and could be just zero).
Patch fixes the issue.

Differential revision: https://reviews.llvm.org/D25327

llvm-svn: 283533
2016-10-07 09:01:04 +00:00
George Rimar b7aec33125 [ELF] - Do not crash when unable to parse ELF object file.
createELFObj() may call error(...), for example when file is too short.
In that case header is not set and following line lead to crash:

EMachine = ELFObj.getHeader()->e_machine;

Patch fixes the issue.

Differential revision: https://reviews.llvm.org/D25233

llvm-svn: 283532
2016-10-07 08:51:57 +00:00
George Rimar 24adce95b2 [ELF] - Make checks in ObjectFile<ELFT>::getSection() stricter.
This patch makes the check for null section stricter, 
so it is only allowed for STT_SECTION symbols now.

Differential revision: https://reviews.llvm.org/D25231

llvm-svn: 283426
2016-10-06 09:17:55 +00:00
Simon Atanasyan 02b9c3f8c3 [ELF] Do not merge sections in case of relocatable object generation
Do not merge sections if generating a relocatable object. It makes
the code simpler because we do not need to update relocations addends
to reflect changes introduced by merging. Instead of that we write
such "merge" sections into separate OutputSections and keep SHF_MERGE
/ SHF_STRINGS flags and sh_entsize value to be able to perform merging
later during a final linking.

Differential Revision: http://reviews.llvm.org/D25066

llvm-svn: 283300
2016-10-05 07:49:18 +00:00
Rui Ueyama af9793d1c1 Add a comment.
llvm-svn: 283229
2016-10-04 16:47:49 +00:00
Eugene Leviant b90f3cf15b [ELF] Don't discard excluded section if -r is used
This conforms to GNU ld/gold behavior and fixes crash in case
excluded section also has associated relocation section

llvm-svn: 283214
2016-10-04 12:05:42 +00:00
George Rimar 0c82561c4c [ELF] - Do not crash if common symbol has alignment 0.
Testcase contains a common symbol with zero alignment,
previously lld would crash, patch fixes that.

Differential revision: https://reviews.llvm.org/D25085

llvm-svn: 283197
2016-10-04 08:49:52 +00:00
George Rimar 10874f70fa [ELF] - Apply clang-format. NFC.
llvm-svn: 283101
2016-10-03 11:13:55 +00:00
Rui Ueyama eb0007aa0c Remove an warning message that can be spammy.
This was intended to warn on a usage error of an ar command.
I was thinking that false positive would be rare because it
has two guards: it warns only when an archive file has no symbols
and contains at least one file.

Turned out that false positive would probably be not that rare.
You wouldn't intentionally create an object file that contains no
exported symbols, but with conditional compile guards, you could
create such file. If it is for a LTO build, you could create an
archive file containing such file. That means there's no way to
detect the usage error in a reliable manner.

This patch simply removes the warning.

llvm-svn: 282916
2016-09-30 19:59:25 +00:00
Rui Ueyama 3d0f77b281 Improve error check for an empty archive.
Previously, it warned on any archive file that has no symbol.
It turned out that that is too noisy.

With this patch, it warns on such archive file that contains no file.

Differential Revision: https://reviews.llvm.org/D25111

llvm-svn: 282885
2016-09-30 17:56:20 +00:00
Rui Ueyama e364d1f431 Add comments.
llvm-svn: 282807
2016-09-29 23:04:50 +00:00
Rui Ueyama d31e13f287 Rename warning -> warn.
It's better because it's a verb.

llvm-svn: 282763
2016-09-29 21:00:23 +00:00
Rui Ueyama d72dd1fc4e Use InputFile::Symbol instead of auto for consistency.
llvm-svn: 282658
2016-09-29 00:58:10 +00:00
Davide Italiano 786d8e33db [ELF/LTO] Switch to the new resolution-based API.
Differential Revision:  https://reviews.llvm.org/D24492

llvm-svn: 282656
2016-09-29 00:40:08 +00:00
Rui Ueyama cb85d7f840 Warn on empty archive files.
Differential Revision: https://reviews.llvm.org/D25044

llvm-svn: 282633
2016-09-28 21:10:54 +00:00
Rafael Espindola 5217f8452c Sort headers. NFC.
llvm-svn: 282603
2016-09-28 16:31:05 +00:00
Eugene Leviant 27be542cdf [ELF] Ignore sections flagged with SHF_EXCLUDE
Differential revision: https://reviews.llvm.org/D24966

llvm-svn: 282568
2016-09-28 08:42:02 +00:00
Rui Ueyama c75ef85e84 Accept sh_entsize = 0.
This surfaced again with Rust. As per bug 30435, rustc creates a
mergeable section with a sh_entsize zero. It bit us before, too.
I think we should relax the input check rather than being too picky.

Differential Revision: https://reviews.llvm.org/D24789

llvm-svn: 282049
2016-09-21 03:22:18 +00:00
Rui Ueyama 38dbd3eea9 Simplify InputFile ownership management.
Previously, all input files were owned by the symbol table.
Files were created at various places, such as the Driver, the lazy
symbols, or the bitcode compiler, and the ownership of new files
was transferred to the symbol table using std::unique_ptr.
All input files were then free'd when the symbol table is freed
which is on program exit.

I think we don't have to transfer ownership just to free all
instance at once on exit.

In this patch, all instances are automatically collected to a
vector and freed on exit. In this way, we no longer have to
use std::unique_ptr.

Differential Revision: https://reviews.llvm.org/D24493

llvm-svn: 281425
2016-09-14 00:05:51 +00:00
Rafael Espindola 10897f1807 Enable merging of SHF_MERGE sections with linker scripts.
This also fixes the related problem of non SHF_MERGE sections with
different flags not being merged.

Fixes pr30355.

llvm-svn: 281338
2016-09-13 14:23:14 +00:00
Rui Ueyama 0eb2a1bd7a Add comments.
llvm-svn: 281265
2016-09-12 21:44:29 +00:00
Michael J. Spencer a9424f39c4 [ELF] Add support for -b binary
Implemented by building an ELF file in memory.

elf, default, and binary match gold behavior.

Differential Revision: https://reviews.llvm.org/D24060

llvm-svn: 281108
2016-09-09 22:08:04 +00:00
Rui Ueyama 478f8eb6ef Add comments.
llvm-svn: 281098
2016-09-09 21:35:38 +00:00
Davide Italiano e02ba98f8f [ELF] Fix DT_NEEDED value.
Differential Revision: https://reviews.llvm.org/D24363

llvm-svn: 280990
2016-09-08 21:18:38 +00:00
Rafael Espindola 042a3f209b Compute section names only once.
This simplifies error handling as there is now only one place in the
code that needs to consider the possibility that the name is
corrupted. Before we would do it in every access.

llvm-svn: 280937
2016-09-08 14:06:08 +00:00
Davide Italiano 29fa6ab7b1 [LTO/InputFiles] Merge two ifs into one. NFCI.
llvm-svn: 280225
2016-08-31 12:27:47 +00:00
George Rimar f21aade0d8 [ELF] - Introduce StripPolicy instead of Config->StripAll/StripDebug flags.
This approach is not only consistent with UnresolvedPolicy, 
but also should help to solve a problem 
of options with opposing meanings, mentioned in PR28843

Differential revision: https://reviews.llvm.org/D23869

llvm-svn: 280206
2016-08-31 08:38:11 +00:00
Rafael Espindola cceb92a075 Pass Binding instead of IsWeak to addBitcode.
We were computing the binding on both the caller and callee.

llvm-svn: 280156
2016-08-30 20:53:26 +00:00
Davide Italiano 35af5b3d21 [LTO] Fix the logic for dropping unnamed_addr.
Differential Revision:  https://reviews.llvm.org/D24037

llvm-svn: 280144
2016-08-30 20:15:03 +00:00
George Rimar 67e3ff83f5 [ELF] - Do not use mergeable sections when LS is used.
After latest changes we combine input sections with 
different attributes into single output section. 
Problem here is that regular output sections does not
support adding mergeable input sections (and vise versa).
Patch just temporarily disables merging for now at 
the same way we do for -O0 for example.

This change helps for linking FreeBSD kernel.

Differential revision: https://reviews.llvm.org/D23447

llvm-svn: 278555
2016-08-12 19:56:57 +00:00
George Rimar 683a35d066 [ELF] - Fix for: error "invalid section index: xxx" when linking FreeBSD kernel.
We found that GNU assembler 2.17.50 [FreeBSD] 2007-07-03
could generate broken objects. STT_SECTION symbols can be
associated with SHT_REL[A]/SHT_SYMTAB/SHT_STRTAB sections.

This is PR28868, patch fixes handling of such files.

Differential revision: https://reviews.llvm.org/D23201

llvm-svn: 278550
2016-08-12 19:25:54 +00:00
Simon Atanasyan 85c6b44817 [ELF][MIPS] Support .MIPS.abiflags section
This section supersedes .reginfo and .MIPS.options sections. But for now
we have to support all three sections for ABI transition period.

llvm-svn: 278482
2016-08-12 06:28:49 +00:00
Rui Ueyama 803568866c Rename functions that handle bitcode files.
getELFKind was overloaded with bitcode files and regular object files,
and I found that is a bit confusing. This patch renames them.

llvm-svn: 277646
2016-08-03 20:33:17 +00:00
Rui Ueyama 7fdb4389a2 Do not instantiate Triple twice.
Also removes redundant variables. NFC.

llvm-svn: 277644
2016-08-03 20:25:29 +00:00
Rui Ueyama 6c50990df6 Add EM_IAMCU support.
This patch adds "-m elf_iamcu" to ldd for IAMCU psABI:
https://github.com/hjl-tools/x86-psABI/wiki/X86-psABI

Patch by H.J Lu.

llvm-svn: 277643
2016-08-03 20:15:56 +00:00
Rui Ueyama 3ebc71eb91 Do not handle zero-sized mergeable section as mergeable.
Mergeable sections with size zero are useless because they don't
actually contain data, and therefore there's no merit ot merge them.
However, in reality, there are object files in the wild containing
such sections. Currently, LLD can't handle them proerply.

This patch makes LLD to handle such sections as if they are non-
mergeable to fix the issue.

Fixes bug 28822.

llvm-svn: 277568
2016-08-03 05:28:02 +00:00
Rui Ueyama 3b452a7a22 Move code for MIPS from createInputSection to initializeSections.
We already have code for ARM in initializeSections, so this
is more consistent.

Differential Revision: https://reviews.llvm.org/D22833

llvm-svn: 276811
2016-07-26 21:26:02 +00:00
Simon Atanasyan 72170d2753 [ELF][MIPS] Use section type to recognize .reginfo and .MIPS.options sections
It is faster and more correct method than string comparision.

llvm-svn: 276807
2016-07-26 21:11:26 +00:00
Rui Ueyama 69c778c084 Implement almost-zero-cost --trace-symbol.
--trace-symbol is a command line option to watch a symbol.
Previosly, we looked up a hash table for a new symbol if the
option is given. Any code that looks up a hash table for each
symbol is expensive because the linker handles a lot of symbols.
In our design, we look up a hash table strictly only once
for a symbol, so --trace-symbol was an exception.

This patch improves efficiency of the option by merging the
hash table into the symbol table.

Instead of looking up a separate hash table with a string,
this patch sets `Traced` flag to symbols specified by --trace-symbol.
So, if you insert a symbol and get a symbol with `Traced` flag on,
you know that you need to print out a log message for the symbol.
This is nearly zero cost.

llvm-svn: 275716
2016-07-17 17:50:09 +00:00
Rui Ueyama 434b56179e Add a pointer to a source file to SymbolBody.
Previously, each subclass of SymbolBody had a pointer to a source
file from which it was created. So, there was no single way to get
a source file for a symbol. We had getSourceFile<ELFT>(), but the
function was a bit inconvenient as it's a template.

This patch makes SymbolBody have a pointer to a source file.
If a symbol is not created from a file, the pointer has a nullptr.

llvm-svn: 275701
2016-07-17 03:11:46 +00:00
Rui Ueyama 818bb2f8dc Remove redundant namespace specifiers.
llvm-svn: 275694
2016-07-16 18:55:47 +00:00
Rui Ueyama 429ef2af6a ELF: Include filenames in error messages.
llvm-svn: 275608
2016-07-15 20:38:28 +00:00
Rui Ueyama 188d2c34e6 Remove variables. NFC.
llvm-svn: 275605
2016-07-15 20:05:05 +00:00
Rui Ueyama 3d9b26b4ad Inline traceUndefined function.
llvm-svn: 275531
2016-07-15 04:57:46 +00:00
Rui Ueyama eba9b63cbc Update comments.
llvm-svn: 275530
2016-07-15 04:57:44 +00:00