Commit Graph

597 Commits

Author SHA1 Message Date
Rafael Espindola a6c4d2f197 Delete needsCopyRelImpl. It is redundant with getRelExpr.
llvm-svn: 267394
2016-04-25 12:05:56 +00:00
Simon Atanasyan c245d84213 [ELF] Delete extra line. NFC
llvm-svn: 267391
2016-04-25 10:18:48 +00:00
Peter Collingbourne 6d01a35ef6 ELF: Forbid undefined symbols with non-default visibility in DSOs.
llvm-svn: 267315
2016-04-24 02:31:04 +00:00
Rafael Espindola 0b9531c8e6 Bring r267164 back with a fix.
The fix is to handle local symbols referring to SHF_MERGE sections.

Original message:

GC entries of SHF_MERGE sections.

It is a fairly direct extension of the gc algorithm. For merge sections
instead of remembering just a live bit, we remember which offsets
were used.

This reduces the .rodata sections in chromium from 9648861 to 9477472
bytes.

llvm-svn: 267233
2016-04-22 22:09:35 +00:00
Peter Collingbourne dadcc17ead ELF: Move Visibility, IsUsedInRegularObj and MustBeInDynSym flags to Symbol.
These are properties of a symbol name, rather than a particular instance
of a symbol in an object file. We can simplify the code by collecting these
properties in Symbol.

The MustBeInDynSym flag has been renamed ExportDynamic, as its semantics
have been changed to be the same as those of --dynamic-list and
--export-dynamic-symbol, which do not cause hidden symbols to be exported.

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

llvm-svn: 267183
2016-04-22 18:42:48 +00:00
Rui Ueyama 467dbdd030 Remove SymPair and instead use two DefinedRegulars instead.
I noticed that I was looking for the definition of SymPair when hacking
the Writer, only to find that it is just a pair of DefinedRegular symbols.
I don't think it provides more values than the cost of using brainpower
to memorize the type. I didn't roll back r266317, which introduced SymPair,
because the patch removes code repetitions. I ported that change to new
code.

llvm-svn: 267047
2016-04-21 20:50:15 +00:00
Rafael Espindola ae605c1b0c Start adding support for internalizing shared libraries.
llvm-svn: 267045
2016-04-21 20:35:25 +00:00
Rafael Espindola e26b50e71a Reduce templating. NFC.
llvm-svn: 267018
2016-04-21 17:37:11 +00:00
Rafael Espindola b312a740ae Delete the needsPlt target hook.
It can be made redundant with getRelExpr.

llvm-svn: 267012
2016-04-21 17:30:24 +00:00
Rafael Espindola 34b335bdf7 Don't recompute getRelExpr. NFC.
llvm-svn: 267005
2016-04-21 16:59:25 +00:00
Rafael Espindola 0c869a752e Moves needsPlt to Writer.cpp.
It was only used there.

llvm-svn: 267002
2016-04-21 16:57:32 +00:00
Simon Atanasyan ca58a8ff5b [ELF][MIPS] Create GOT entries for R_MIPS_REL32 dynamic relocations
MIPS ABI turns using of GOT and dynamic relocations inside out. While
regular ABI uses dynamic relocations to fill up GOT entries MIPS ABI
requires dynamic linker to fills up GOT entries using specially sorted
dynamic symbol table. This affects even dynamic relocations against
symbols which do not require GOT entries creation explicitly, i.e. do
not have any GOT-relocations. So if a preemptible symbol has a dynamic
relocation we anyway have to create a GOT entry for it.

If a non-preemptible symbol has a dynamic relocation against it, dynamic
linker takes it st_value, adds offset and writes down result of the
dynamic relocation. In case of preemptible symbol dynamic linker
performs symbol resolution, writes the symbol value to the GOT entry and
reads the GOT entry when it needs to perform a dynamic relocation.

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

llvm-svn: 266921
2016-04-20 21:40:33 +00:00
Rui Ueyama 07320e4030 ELF: Template LinkerScript class.
Originally, linker scripts were basically an alternative way to specify
options to the command line options. But as we add more features to hanlde
symbols and sections, many member functions needed to be templated.
Now most the members are templated. It is probably time to template the
entire class.

Previously, LinkerScript is an executor of the linker script as well as
a storage of linker script configurations. This is not suitable to template
the class because when we are reading linker script files, we don't know
the ELF type yet, so we can't instantiate ELF-templated classes.

In this patch, I defined a new class, ScriptConfiguration, to store
linker script configurations. ScriptParser writes parse results to it,
and LinkerScript uses them.

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

llvm-svn: 266908
2016-04-20 20:13:41 +00:00
Rafael Espindola c6b17bdc29 Delete refersToGotEntry.
It can be computed from the expression.

llvm-svn: 266890
2016-04-20 17:30:22 +00:00
Rafael Espindola 475dbf42e4 Simplify mips gp0 handling.
In all currently supported cases this is a nop.

llvm-svn: 266888
2016-04-20 17:20:49 +00:00
Rafael Espindola 2081dbcc7a Inline canRelaxTls.
It was always called in a position where the relocation type was already
known.

llvm-svn: 266880
2016-04-20 15:01:42 +00:00
Rafael Espindola f54413c18e Simplify canRelaxTls.
Check isTls in the called and pass a SymbolBody&.

llvm-svn: 266879
2016-04-20 14:52:18 +00:00
Rafael Espindola cc36a63f0b Move canRelaxTls to Writer.cpp. NFC.
llvm-svn: 266878
2016-04-20 14:41:55 +00:00
Rafael Espindola 6eda85ac1f Delete needsDynRelative.
It is now redundant. Writer.cpp can reason that 2 dynamic relocations
are needed: one to find the final got entry address and one to fill the
got entry.

llvm-svn: 266876
2016-04-20 14:36:24 +00:00
Rafael Espindola 58cd5db4ef Simplify mips got handling.
This avoids computing the address of a position in the got just to then
subtract got->getva().

llvm-svn: 266831
2016-04-19 22:46:03 +00:00
Rafael Espindola 5bf59728e2 Remove isGotRelative.
It is now redundant with the expression. While at it, handle both "X -
Got" and "Got - PC".

llvm-svn: 266607
2016-04-18 12:31:37 +00:00
Rafael Espindola 3f5d634c73 Have getRelExpr handle all cases on x86.
This requires adding a few more expression types, but is already a small
simplification. Having Writer.cpp know the exact expression will also
allow further simplifications.

llvm-svn: 266604
2016-04-18 12:07:13 +00:00
Rafael Espindola 99c224787b Delete the now redundant pointsToLocalDynamicGotEntry.
llvm-svn: 266584
2016-04-18 01:34:20 +00:00
Rafael Espindola df17277d72 Have getRelExpr return the final values for tls gd.
llvm-svn: 266583
2016-04-18 01:29:15 +00:00
Rafael Espindola c4d56970dc Change getRelExpr to return the final value for TLSLD. NFC.
llvm-svn: 266580
2016-04-18 00:28:57 +00:00
George Rimar 652852c5c0 Recommitted 266457 with fix:
* Do script driven layout only if SECTIONS section exist.

Initial commit message:

[ELF] - Implemented basic location counter support.

This patch implements location counter support. 
It also separates assign addresses for sections to assignAddressesScript() if it scipt exists.

Main testcase is test/ELF/linkerscript-locationcounter.s, It contains some work with location counter. It is basic now.
Implemented location counter assignment and '+' operations.

Patch by myself with LOTS of comments and design suggestions from Rui Ueyama.

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

llvm-svn: 266526
2016-04-16 10:10:32 +00:00
Rui Ueyama faac567e68 Revert r266457: "[ELF] - Implemented basic location counter support."
This reverts commit r266457 as it breaks "hello world" both on
Linux and FreeBSD.

llvm-svn: 266485
2016-04-15 22:39:27 +00:00
Rafael Espindola 5628ee7631 Simplify got handling.
Each getRelExpr is now expected to return the correct got expression
instead of having Writer patch it up with needsGot.

llvm-svn: 266466
2016-04-15 19:14:18 +00:00
George Rimar ea25877d4a [ELF] - Implemented basic location counter support.
This patch implements location counter support. 
It also separates assign addresses for sections to assignAddressesScript() if it scipt exists.

Main testcase is test/ELF/linkerscript-locationcounter.s, It contains some work with location counter. It is basic now.
Implemented location counter assignment and '+' operations.

Patch by myself with LOTS of comments and design suggestions from Rui Ueyama.

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

llvm-svn: 266457
2016-04-15 17:44:19 +00:00
Rafael Espindola 38c67a27fe Store a Symbol for EntrySym.
This makes it impossible to forget to call repl on the SymbolBody.

llvm-svn: 266432
2016-04-15 14:41:56 +00:00
Rafael Espindola 69a38060a8 Don't create relocations for absolute got entries.
llvm-svn: 266427
2016-04-15 12:44:43 +00:00
Rafael Espindola f8f6ad74a0 Don't create relocations for non preemptable absolute symbols.
llvm-svn: 266425
2016-04-15 12:22:22 +00:00
Rafael Espindola 3666025880 Two small related fixes.
* A hidden undefined is not preemptable.
* It is always zero, so we don't need a dynamic reloc for it.

llvm-svn: 266424
2016-04-15 11:57:07 +00:00
Simon Atanasyan 1ca263c890 [ELF][MIPS] Make R_MIPS_LO16 a relative relocation if it references _gp_disp symbol
The _gp_disp symbol designates offset between start of function and 'gp'
pointer into GOT. The following code is a typical MIPS function preamble
used to setup $gp register:

lui    $gp, %hi(_gp_disp)
addi   $gp, $gp, %lo(_gp_disp)

To calculate R_MIPS_HI16 / R_MIPS_LO16 relocations results we use
the following formulas:

%hi(_gp - P + A)
%lo(_gp - P + A + 4),
where _gp is a value of _gp symbol, A is addend, and P current address.

The R_MIPS_LO16 relocation references _gp_disp symbol is always the second
instruction. That is why we need four byte adjustments. The patch assigns
R_PC type for R_MIPS_LO16 relocation and adjusts its addend by 4. That fix
R_MIPS_LO16 calculation.

For details see p. 4-19 at ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf

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

llvm-svn: 266368
2016-04-14 21:10:05 +00:00
Rafael Espindola 7f0b727235 Specialize the symbol table data structure a bit.
We never need to iterate over the K,V pairs, so we can avoid copying the
key as MapVector does.

This is a small speedup on most benchmarks.

llvm-svn: 266364
2016-04-14 20:42:43 +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 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
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