Commit Graph

63 Commits

Author SHA1 Message Date
Simon Atanasyan 09dae7c3e7 [ELF][MIPS] Handle R_MIPS_HI16/LO16 relocations against _gp_disp symbol
The `_gp_disp` is a magic symbol designates offset between start of
function and gp pointer into GOT. Only `R_MIPS_HI16` and `R_MIPS_LO16`
relocations are permitted with `_gp_disp`. The patch adds the `_gp_disp`
as an ignored symbol and adjusts symbol value before call the `relocateOne`
for `R_MIPS_HI16/LO16` relocations.

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

llvm-svn: 255768
2015-12-16 14:45:09 +00:00
George Rimar a5fbebc206 [ELF] - Implemented --print-gc-sections command line argument.
List all sections removed by garbage collection. This option is only effective if garbage collection has been enabled via the `--gc-sections' option.

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

llvm-svn: 255235
2015-12-10 09:12:18 +00:00
Rui Ueyama 7b19c34550 Revert "ELF: Make .note.GNU-stack more compatible with traditional linkers."
This reverts commit r253797 because it was based on a misunderstanding
that lld wouldn't work on NetBSD without this change.

llvm-svn: 254003
2015-11-24 18:48:16 +00:00
George Rimar e3336c0be6 Reapply fixed r253967.
llvm-svn: 253971
2015-11-24 10:15:50 +00:00
George Rimar 11721ce810 Revert r253967 which broke buildbot.
llvm-svn: 253970
2015-11-24 10:04:22 +00:00
George Rimar 63a6ca9150 [ELF] Implements -z relro: create an ELF "PT_GNU_RELRO" segment header in the object.
Partial (-z relro) and full (-z relro, -z now) relro cases are implemented.

Partial relro:
The ELF sections are reordered so that the ELF internal data sections (.got, .dtors, etc.) precede the program's data sections (.data and .bss).
.got is readonly, .got.plt is still writeable.

Full relro:
Supports all the features of partial RELRO, .got.plt is also readonly.

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

llvm-svn: 253967
2015-11-24 09:44:28 +00:00
Rui Ueyama e79b09a616 ELF: Make .note.GNU-stack more compatible with traditional linkers.
With this patch, lld creates PT_GNU_STACK segments only when all input
files have .note.GNU-stack sections. This is in line with other linkers
with a minor difference (we don't care about .note.GNU-stack rwx bits as
you can always remove .note.GNU-stack sections instead of setting x bit.)

At least, NetBSD loader does not understand PT_GNU_STACK segments and
reject any executables that have the section. This patch makes lld
compatible with such operating systems.

llvm-svn: 253797
2015-11-21 22:19:32 +00:00
Rui Ueyama 03bec877c5 Remove default values that are always overriden in Driver.cpp.
llvm-svn: 253710
2015-11-20 21:00:42 +00:00
George Rimar 03220309e1 [ELF2] - Implemented PT_GNU_STACK support, -z execstack option.
PT_GNU_STACK is a entry in the elf file format which contains the access rights (read, write, execute) of the stack,
it is always generated now. By default stack is not executable in this implementation. 
-z execstack can be used to make executable.

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

llvm-svn: 253145
2015-11-14 20:56:08 +00:00
Denis Protivensky 8e3b38aba1 [ELF2] SECTIONS command basic support
* determine output section by input section name
* discard input sections
* order output sections accordingly

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

llvm-svn: 252868
2015-11-12 09:52:08 +00:00
George Rimar 5dad7c1d4c Reapply r251144: fixed test.
llvm-svn: 251184
2015-10-24 08:52:46 +00:00
Rui Ueyama b621d1ae58 Revert "[ELF2] --strip-all/-s command line implemented"
This reverts commit r251144 because the new test is failing.

llvm-svn: 251148
2015-10-23 21:08:41 +00:00
George Rimar 236bf3bfe4 [ELF2] --strip-all/-s command line implemented
-s, --strip-all - Strip all symbols
Implementation removes .strtab and .symtab sections from output.

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

llvm-svn: 251144
2015-10-23 20:24:44 +00:00
Rafael Espindola 2c1217d82a Parse and store the value of the -O option.
llvm-svn: 251136
2015-10-23 19:02:19 +00:00
Rui Ueyama c4aaed9255 ELF2: Implement --gc-sections.
Section garbage collection is a feature to remove unused sections
from outputs. Unused sections are sections that cannot be reachable
from known GC-root symbols or sections. Naturally the feature is
implemented as a mark-sweep garbage collector.

In this patch, I added Live bit to InputSectionBase. If and only
if Live bit is on, the section will be written to the output.
Starting from GC-root symbols or sections, a new function, markLive(),
visits all reachable sections and sets their Live bits. Writer then
ignores sections whose Live bit is off, so that such sections are
excluded from the output.

This change has small negative impact on performance if you use
the feature because making sections means more work. The time to
link Clang changes from 0.356s to 0.386s, or +8%.

It reduces Clang size from 57,764,984 bytes to 55,296,600 bytes.
That is 4.3% reduction.

http://reviews.llvm.org/D13950

llvm-svn: 251043
2015-10-22 18:49:53 +00:00
Igor Kudrin 1b0d7066ff [ELF2] Add support for GNU Hash section
This patch implements --hash-style command line switch.

* By default, or with "sysv" or "both" parameters, the linker generates
  a standard ELF hash section.
* With "gnu" or "both", it produces a GNU-style hash section.

That section requires the symbols in the dynamic symbol table section, which
are referenced in the GNU hash section, to be placed after not hashed ones and
to be sorted to correspond the order of hash buckets in the GNU Hash section.

The division function, as well as estimations for the section's parameters,
are just the first rough attempt and the subjects for further adjustments.

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

llvm-svn: 251000
2015-10-22 08:21:35 +00:00
Davide Italiano 6e91c598b9 [ELF2] Add support for -z origin.
llvm-svn: 250907
2015-10-21 17:09:47 +00:00
Davide Italiano 88f476b9eb [ELF2] Introduce support for -z nodelete.
llvm-svn: 250771
2015-10-20 00:20:20 +00:00
George Rimar 83f406cff5 [ELF2] - Linker script EXTERN command implemented.
The reason of collecting all undefines in vector is that during reading files we already need to have Symtab created. Or like was done in that patch - to put undefines from scripts somewhere to delay Symtab.addUndefinedOpt() call.

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

llvm-svn: 250711
2015-10-19 17:35:12 +00:00
Rui Ueyama 6455852a28 ELF2: Treat IsMips64EL as a global configuration.
If one file is MIPS64EL, all files are MIPS64EL, and vice versa.
We do not have to look up MIPS-ness for each file. Currently we
do not support 64-bit MIPS, so the config value is always false.

llvm-svn: 250566
2015-10-16 22:51:43 +00:00
Rui Ueyama 2b675074fe ELF2: Support --entry=<addr>.
If an argument for --entry is a number, that's not a symbol name but
an absolute address. If that's the case, the address is directly set
to ELF header's e_entry.

llvm-svn: 250334
2015-10-14 22:20:57 +00:00
Davide Italiano cebb449e11 [ELF2] Add support for -Bsymbolic.
llvm-svn: 250225
2015-10-13 21:02:34 +00:00
Rui Ueyama e717a7195b ELF2: Rename ElfKind -> EKind.
ELFKind as a type name and ElfKind is a variable name was too subtle.

llvm-svn: 250172
2015-10-13 16:20:50 +00:00
Rafael Espindola af70764aa1 Simplify the InputFile type hierarchy.
Now that the SymbolTable is templated, we don't need the ELFData class or
multiple inheritance.

llvm-svn: 250005
2015-10-12 01:55:32 +00:00
Rui Ueyama 35da9b6e1c ELF2: Implement --as-needed.
This patch adds AsNeeded and IsUsed bool fields to SharedFile. AsNeeded bit
is set if the DSO is enclosed with --as-needed and --no-as-needed. IsUsed
bit is off by default. When we adds a symbol to the symbol table for dynamic
linking, we set its SharedFile's IsUsed bit.

If AsNeeded is set but IsUsed is not set, we don't want to write that
file's SO name to DT_NEEDED field.

http://reviews.llvm.org/D13579

llvm-svn: 249998
2015-10-11 20:59:12 +00:00
Rafael Espindola 9afbac479f Handle a crash in conflict detection with archive members.
llvm-svn: 249996
2015-10-11 20:19:20 +00:00
Rafael Espindola 525914defd Detect incompatible files when one of them comes from an archive.
llvm-svn: 249968
2015-10-11 03:36:49 +00:00
Rui Ueyama 52a1509ea7 ELF2: LinkerScript: Interpret -l and = file name prefixes.
In the linker script, -l and = have the same meaning as in the command line.
In addition to that, if a path is not absolute, the path needs to be searched
from the search paths. This patch implements them.

llvm-svn: 249967
2015-10-11 03:28:42 +00:00
Rui Ueyama a467240309 ELF2: Add --verbose.
It is currently not actually verbose but rather terse,
but that's intentional.

llvm-svn: 249964
2015-10-11 02:03:03 +00:00
Rui Ueyama ff77768569 ELF2: Move Target and entry initialization from SymbolTable to Driver.
SymbolTable was not a right place for initialization. We had to do that
because Driver didn't know what type of ELF objects are being handled.
We taught Driver that, so we can now move this code to Driver.

llvm-svn: 249904
2015-10-09 21:12:40 +00:00
Rui Ueyama 3ce825ed26 ELF2: Make SymbolTable a template class.
SymbolTable was not a template class. Instead we had switch-case-based
type dispatch to call desired functions. We had to do that because
SymbolTable was created before we know what ELF type objects had been
passed.

Every time I tried to add a new function to the symbol table, I had to
define a dispatcher which consist of a single switch statement.

It also brought an restriction what the driver can do. For example,
we cannot add undefined symbols before any files are added to the symbol
table. That's because no symbols can be added until the symbol table
knows the ELF type, but when it knows about that, it's too late.

In this patch, the driver makes a decision on what ELF type objects
are being handled. Then the driver creates a SymbolTable object for
an appropriate ELF type.

http://reviews.llvm.org/D13544

llvm-svn: 249902
2015-10-09 21:07:25 +00:00
Rui Ueyama fe7eeed585 ELF2: Sort. NFC.
llvm-svn: 249803
2015-10-09 02:46:28 +00:00
Rui Ueyama 2cac5843a0 ELF2: Define a utility function to handle simple command line options.
llvm-svn: 249592
2015-10-07 19:34:51 +00:00
George Rimar 97aad172b8 [ELF2] -z now option implemented
When generating an executable or shared library, mark it to tell the dynamic linker to resolve all symbols when the program is started, or when the shared library is linked to using dlopen, instead of deferring function call resolution to the point when the function is first called.

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

llvm-svn: 249551
2015-10-07 15:00:21 +00:00
Denis Protivensky 1ef7b3ff55 [ELF2] Handle -m option
Parse and apply emulation given with -m option.
Check input files to match ELF type and machine architecture provided with -m.

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

llvm-svn: 249529
2015-10-07 09:13:03 +00:00
Rui Ueyama ee59282bfd ELF2: Implement OUTPUT() linker script directive.
llvm-svn: 249491
2015-10-07 00:25:09 +00:00
Davide Italiano aad4402097 [ELF2] Address r249428 post comit review. Style + test trim.
llvm-svn: 249451
2015-10-06 20:02:15 +00:00
Davide Italiano c39c75dee4 [ELF2] Implement --{enable, disable}-new-dtags options.
llvm-svn: 249428
2015-10-06 16:20:00 +00:00
Igor Kudrin b1f2b51a89 [ELF2] Add DT_INIT and DT_FINI dynamic table entries
The entries are added if there are "_init" or "_fini" entries in
the symbol table respectively. According to the behavior of ld,
entries are inserted even for undefined symbols.

Symbol names can be overridden by using -init and -fini command
line switches. If used, these switches neither add new symbol table
entries nor require those symbols to be resolved.

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

llvm-svn: 249297
2015-10-05 10:29:46 +00:00
George Rimar 57e40deb8d [ELF2] Implement --no-undefined flag.
llvm-svn: 249064
2015-10-01 20:14:45 +00:00
Rui Ueyama 7de3f3719a ELF2: Add -soname option.
llvm-svn: 249058
2015-10-01 19:36:04 +00:00
Igor Kudrin 2696bbeb93 [ELF2] Add --[no-]whole-archive command line switches
Summary:
If --whole-archive is used, all symbols from the following archives are added to the output. --no-whole-archive restores default behavior. These switches can be used multiple times.

NB. We have to keep an ArchiveFile instance within SymbolTable even if --whole-archive mode is active since it can be a thin archive which contains just names of external files. In that case actual memory buffers for the archive members will be stored within the File member of ArchiveFile class.

Reviewers: rafael, ruiu

Subscribers: grimar, llvm-commits

Projects: #lld

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

llvm-svn: 249045
2015-10-01 18:02:21 +00:00
Igor Kudrin d912ee9595 [ELF2] Add -Bstatic and -Bdynamic command line switches
Summary:
These switches affect library searching for '-l' which follow them. Synonym forms are also supported:
* -dy and -call_shared for -Bdynamic switch
* -dn, -non_shared and -static for -Bstatic switch 

Reviewers: rafael, ruiu

Subscribers: emaste, llvm-commits

Projects: #lld

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

llvm-svn: 249029
2015-10-01 16:42:03 +00:00
Rui Ueyama 7971152589 ELF2: Do not set default values that will always be overwritten.
These member variables are overwritten unconditionally by Driver,
so setting default values would be confusing.

llvm-svn: 248922
2015-09-30 17:26:13 +00:00
Rui Ueyama 4993d0eb51 ELF2: Sort Config member variables. NFC.
llvm-svn: 248838
2015-09-29 22:33:21 +00:00
Rui Ueyama 4eed0114c5 ELF2: Use 'a.out' as default output file name.
llvm-svn: 248831
2015-09-29 21:49:40 +00:00
Rui Ueyama 9d4c6d771b [ELF2] Implemented --entry flag.
Patch from George Rimar!

llvm-svn: 248806
2015-09-29 16:40:13 +00:00
Rafael Espindola 4b2ca85c1a Implement --allow-multiple-definition.
Patch by George Rimar!

llvm-svn: 248733
2015-09-28 20:30:11 +00:00
Igor Kudrin 1309fc0378 [ELF2] Add --sysroot command line switch
Reviewers: rafael, ruiu

Subscribers: llvm-commits

Projects: #lld

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

llvm-svn: 248715
2015-09-28 15:01:59 +00:00
Rafael Espindola eb990af31e Trying to fix the windows build.
llvm-svn: 248709
2015-09-28 13:11:36 +00:00