Commit Graph

1478 Commits

Author SHA1 Message Date
Rafael Espindola c9157d35d9 Hash symbol names only once per global SymbolBody.
The DenseMap doesn't store hash results. This means that when it is
resized it has to recompute them.

This patch is a small hack that wraps the StringRef in a struct that
remembers the hash value. That way we can be sure it is only hashed
once.

llvm-svn: 266357
2016-04-14 19:17:16 +00:00
Rafael Espindola 3151d89595 Simplify handling of size relocations. NFC.
llvm-svn: 266355
2016-04-14 18:39:44 +00:00
George Rimar 5cfd306e00 Move variables closer to code scopes that uses them. NFC.
llvm-svn: 266340
2016-04-14 17:05:56 +00:00
Rafael Espindola e149b488af Remove the only case where we would relocate a R_386_TLS_TPOFF.
llvm-svn: 266330
2016-04-14 16:05:42 +00:00
Rafael Espindola c1c14a227e Merge duplicated cases. NFC.
llvm-svn: 266328
2016-04-14 15:56:14 +00:00
Rafael Espindola 735bbaa1d9 Add missing typename.
llvm-svn: 266318
2016-04-14 14:40:38 +00:00
George Rimar 8bbff7ec85 [ELF] - Refactoring of end/edata/etext implementation.
Minor refactoring of how end/edata/etext symbols are handled.

Differential revision: http://reviews.llvm.org/D19109

llvm-svn: 266317
2016-04-14 14:37:59 +00:00
George Rimar 4c2ae3a171 Return back the zero parameter of aggregate initialization in OutputSectionFactory::lookup().
That was removed in r266304, but leads to warnings by Clang.
Thanks to Rafael Espíndola for pointing on that.

Though I think change was legal from point of C++.

llvm-svn: 266306
2016-04-14 14:24:23 +00:00
George Rimar d502f47726 Make OutputSectionFactory::lookup() inline. NFC.
Also I removed the last zero parameter of 
aggregate initialization as it is excessive here.

llvm-svn: 266304
2016-04-14 14:07:54 +00:00
George Rimar 2122168912 Removed excessive line. NFC.
llvm-svn: 266303
2016-04-14 13:56:28 +00:00
George Rimar 0fa18b8923 Reduce expression to single line. NFC.
llvm-svn: 266302
2016-04-14 13:47:04 +00:00
George Rimar ee741cfa5f Clang formated file. NFC.
llvm-svn: 266299
2016-04-14 13:23:02 +00:00
George Rimar 4e8cf85b74 Combine code branch into single line. NFC.
llvm-svn: 266298
2016-04-14 13:00:03 +00:00
Peter Collingbourne 0a68cf50f8 ELF: Do not create copy relocations for references in writable sections.
They are unnecessary, as the dynamic loader can apply the original relocations
directly. This was also resulting in the creation of copy relocations in PIEs.

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

llvm-svn: 266273
2016-04-14 01:48:11 +00:00
Rafael Espindola 3fa7352fc7 Fix warning about unused variable.
llvm-svn: 266232
2016-04-13 19:09:48 +00:00
Rafael Espindola ab14c88984 git-clang-format. NFC.
llvm-svn: 266231
2016-04-13 19:07:40 +00:00
Rafael Espindola f9d3dcf0a8 Don't set MustBeInDynSym for hidden symbols.
llvm-svn: 266230
2016-04-13 19:03:34 +00:00
Adhemerval Zanella 9df0720766 ELF: Implement --dynamic-list
This patch implements the --dynamic-list option, which adds a list of
global symbol that either should not be bounded by default definition
when creating shared libraries, or add in dynamic symbol table in the
case of creating executables.

The patch modifies the ScriptParserBase class to use a list of Token
instead of StringRef, which contains information if the token is a
quoted or unquoted strings. It is used to use a faster search for
exact match symbol name.

The input file follow a similar format of linker script with some
simplifications (it does not have scope or node names). It leads
to a simplified parser define in DynamicList.{cpp,h}.

Different from ld/gold neither glob pattern nor mangled names
(extern 'C++') are currently supported.

llvm-svn: 266227
2016-04-13 18:51:11 +00:00
George Rimar 2a78fceb2c [ELF] - Change -t implementation to print which archive members are used.
Previously each archive file was reported no matter were it's member used or not,
like:
lib/libLLVMSupport.a

Now lld prints line for each used internal file, like:
lib/libLLVMSupport.a(lib/Support/CMakeFiles/LLVMSupport.dir/StringSaver.cpp.o)
lib/libLLVMSupport.a(lib/Support/CMakeFiles/LLVMSupport.dir/Host.cpp.o)
lib/libLLVMSupport.a(lib/Support/CMakeFiles/LLVMSupport.dir/ConvertUTF.c.o)

That should be consistent with what gold do.

This fixes PR27243.

Differential revision: http://reviews.llvm.org/D19011

llvm-svn: 266220
2016-04-13 18:07:57 +00:00
Peter Collingbourne f6e9b4ec24 ELF: Use hidden visibility for all DefinedSynthetic symbols.
This simplifies the code by allowing us to remove the visibility argument
to functions that create synthetic symbols.

The only functional change is that the visibility of the MIPS "_gp" symbol
is now hidden. Because this symbol is defined in every executable or DSO, it
would be difficult to observe a visibility change here.

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

llvm-svn: 266208
2016-04-13 16:57:28 +00:00
Peter Collingbourne 1f71d748ae ELF: Do not create relative relocations for undefined symbols.
We need to ensure that the address of an undefined weak symbol evaluates to
zero. We were getting this right for non-PIC executables (where the symbol
can be evaluated directly) and for DSOs (where we emit a symbolic relocation
for these symbols, as they are preemptible). But we weren't getting it right
for PIEs. Probably the simplest way to ensure that these symbols evaluate
to zero is by not creating a relocation in .got for them.

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

llvm-svn: 266161
2016-04-13 02:24:48 +00:00
Rafael Espindola 22ef956a45 Change how we apply relocations.
With this patch we use the first scan over the relocations to remember
the information we found about them: will them be relaxed, will a plt be
used, etc.

With that the actual relocation application becomes much simpler. That
is particularly true for the interfaces in Target.h.

This unfortunately means that we now do two passes over relocations for
non SHF_ALLOC sections. I think this can be solved by factoring out the
code that scans a single relocation. It can then be used both as a scan
that record info and for a dedicated direct relocation of non SHF_ALLOC
sections.

I also think it is possible to reduce the number of enum values by
representing a target with just an OutputSection and an offset (which
can be from the start or end).

This should unblock adding features like relocation optimizations.

llvm-svn: 266158
2016-04-13 01:40:19 +00:00
Peter Collingbourne 173ee84530 ELF: Give automatically generated __start_* and __stop_* symbols hidden visibility.
These symbols describe a property of a linkage unit, so it seems reasonable
to limit their visibility to the linkage unit. Furthermore the use cases I
am aware of do not require more than hidden visibility.

This is a departure from the behavior of the bfd and gold linkers. However,
it is unclear that the decision to give these symbols default visibility
in those linkers was made deliberately. The __start_*/__stop_* feature
was added to the bfd linker in 1994 [1], while the visibility feature was
added about five years later [2], so it may have been that the visibility
of these symbols was not considered. The feature was implemented in gold
[3] in the same way; the behavior may have simply been copied from bfd.

The only related discussion I could find on the binutils mailing list [4]
was a user issue which would most likely not have occurred if the symbols
had hidden visibility.

[1] https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=5efddb2e7c3229b569a862205f61d42860af678b
[2] https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=0fc731e447cd01e7fc35197b487ff0e4fd25afca
[3] https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=bfd58944a64b0997a310b95fbe0423338961e71c
[4] https://sourceware.org/ml/binutils/2014-05/msg00011.html

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

llvm-svn: 266121
2016-04-12 20:41:42 +00:00
Rafael Espindola 6f92e14ce2 Use DefinedSynthetic for _gp* symbols.
The test changes to put _gp* in the .got section matches what both bfd
and gold do.

llvm-svn: 266067
2016-04-12 13:26:51 +00:00
Rafael Espindola 3a72cc0083 Simplify now that we always have a .got.
llvm-svn: 266064
2016-04-12 13:23:27 +00:00
Rafael Espindola a22b082e46 Always create a .got on mips.
The _gp* family of symbols is defined as an offset in .got, and it is
not at all clear what should happen when .got is not defined.

This will allow some simplifications on how these symbols are handled.

llvm-svn: 266063
2016-04-12 13:21:13 +00:00
Rafael Espindola 9b3f99e50f Devide _gp in the same spot as other mips symbols. NFC.
The test changes are just because of the symbol order.

llvm-svn: 266037
2016-04-12 02:24:43 +00:00
Davide Italiano 15c41b25c7 [LTO] Switch Module to std::unique_ptr<>.
Differential Revision:   http://reviews.llvm.org/D18994

llvm-svn: 266009
2016-04-11 22:39:51 +00:00
Rafael Espindola 8396f72f7b Simplify handling of mips gp* symbols.
Give them values instead of computing it during relocation.

llvm-svn: 265986
2016-04-11 20:34:27 +00:00
Rafael Espindola 03ef404e97 Simplify the creation of __rel[a]_iplt_{start,end}.
They can be regular DefinedSynthetic.

llvm-svn: 265981
2016-04-11 19:14:59 +00:00
Peter Collingbourne c98de13871 ELF: Set FDE count in .eh_frame_hdr correctly.
It is possible to have FDEs with duplicate PCs if ICF was able to merge
functions with FDEs, or if the input files for some reason contained duplicate
FDEs.  We previously weren't handling this correctly when producing the
contents of the .eh_frame_hdr section; we were dropping entries and leaving
null entries at the end of the section, which confused consumers of unwind
data, such as the backtrace() function.

Fix the bug by setting the FDE count to the number of FDEs actually emitted
into .eh_frame_hdr, rather than the number of FDEs in .eh_frame.

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

llvm-svn: 265957
2016-04-11 16:40:08 +00:00
Peter Collingbourne 7cf73ec4c7 ELF: Implement basic support for module asm in bitcode files.
Differential Revision: http://reviews.llvm.org/D18872

llvm-svn: 265956
2016-04-11 16:39:43 +00:00
Rafael Espindola 34ffcbbe84 Mark OffsetSec const. NFC.
llvm-svn: 265940
2016-04-11 13:51:23 +00:00
Rafael Espindola ac568f9ea4 Remove initializer that are always set by the constructor.
llvm-svn: 265939
2016-04-11 13:47:35 +00:00
Rafael Espindola 571452c11f Mark a few methods const.
llvm-svn: 265938
2016-04-11 13:44:05 +00:00
Simon Atanasyan 2615c3846f [ELF] Do not skip relocation scanning checking if the symbol gets dynamic COPY relocation already
It is possible that the same symbol referenced by two kinds of
relocations at the same time. The first type requires say GOT entry
creation, the second type requires dynamic copy relocation. For MIPS
targets they might be R_MIPS_GOT16 and R_MIPS_HI16 relocations. For X86
target they might be R_386_GOT32 and R_386_32 respectively.

Now LLD never creates GOT entry for a symbol if this symbol already has
related copy relocation. This patch solves this problem.

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

llvm-svn: 265910
2016-04-10 21:48:55 +00:00
Rui Ueyama 029d89ee57 Fix another crash bug in --start-lib.
The previous fix didn't work for bitcode files. This patch fixes
the remaining issue.

llvm-svn: 265854
2016-04-08 21:38:22 +00:00
Rui Ueyama 1f492893ac Fix a crash bug in --start-lib.
Previously, Lazy symbols were created for undefined symbols even though
such symbols cannot be resolved by loading object files. This patch
fixes that bug.

llvm-svn: 265847
2016-04-08 20:49:31 +00:00
Rafael Espindola 8caf33c483 Cleanup the handling of MustBeInDynSym and IsUsedInRegularObj.
Now MustBeInDynSym is only true if the symbol really must be in the
dynamic symbol table.

IsUsedInRegularObj is only true if the symbol is used in a .o or -u. Not
a .so or a .bc.

A benefit is that this is now done almost entirilly during symbol
resolution. The only exception is copy relocations because of aliases.

This includes a small fix in that protected symbols in .so don't force
executable symbols to be exported.

This also opens the way for implementing internalize for -shared.

llvm-svn: 265826
2016-04-08 18:39:03 +00:00
Rafael Espindola a15fb15b05 Don't lower the visibility because of shared symbols.
If a shared library has a protected symbol 'foo', that doesn't imply
that the symbol 'foo' in the output should be protected or not.

llvm-svn: 265794
2016-04-08 16:11:42 +00:00
Rafael Espindola b729b2131d Produce STV_DEFAULT for symbols in shared libraries.
The spec says:
If a symbol definition with STV_PROTECTED visibility from a shared
object is taken as resolving a reference from an executable or another
shared object, the SHN_UNDEF symbol table entry created has STV_DEFAULT
visibility.

llvm-svn: 265792
2016-04-08 15:43:43 +00:00
Rafael Espindola badd397aa7 Make getSymbolBinding a local static. NFC.
llvm-svn: 265791
2016-04-08 15:30:56 +00:00
Adhemerval Zanella 15cba9e7e5 [lld] [ELF/AARCH64] Fix dynamic relocation from PIC GOT access
This patch fixes dynamic relocation creation from GOT access in dynamic
objects on aarch64. Current code creates a plt relative one
(R_AARCH64_JUMP_SLOT) instead of a got relative (R_AARCH64_GLOB_DAT).

It leads the programs fails with:

$ cat t.cc

std::string test = "hello...\n";

int main ()
{
  printf ("%s\n", test.c_str());
  return 0;
}
$ clang++ t.cc -fpic -o t
$ ./t
hello...

Segmentation fault (core dumped)

Due the fact it will try to access the plt instead of the got for
__cxa_atexit registration for the std::string destruction.  It will
lead in a bogus function address in atexit.

llvm-svn: 265784
2016-04-08 14:10:41 +00:00
Rui Ueyama 57bbdaf937 Simplify createELFFile. NFC.
llvm-svn: 265758
2016-04-08 00:18:25 +00:00
Rui Ueyama 4655ea3ff8 Define a helper function to simplify. NFC.
llvm-svn: 265757
2016-04-08 00:14:55 +00:00
Rui Ueyama 6c8b0c1b96 Use EM_NONE instead of 0 to represent an invalid value. NFC.
llvm-svn: 265750
2016-04-07 23:54:33 +00:00
Rui Ueyama d86ec30168 ELF: Add --build-id=sha1 option.
llvm-svn: 265748
2016-04-07 23:51:56 +00:00
Peter Collingbourne e217660591 ELF: Ignore --detect-odr-violations flag.
Differential Revision: http://reviews.llvm.org/D18877

llvm-svn: 265744
2016-04-07 23:15:50 +00:00
Rui Ueyama 3a41be277a ELF: Implement --build-id=md5.
Previously, we supported only one hash function, FNV-1, so
BuildIdSection directly handled hash computation. In this patch,
I made BuildIdSection an abstract class and defined two subclasses,
BuildIdFnv1 and BuildIdMd5.

llvm-svn: 265737
2016-04-07 22:49:21 +00:00
Rui Ueyama 5d92af65d3 Sort options.
llvm-svn: 265724
2016-04-07 21:10:42 +00:00