Commit Graph

697 Commits

Author SHA1 Message Date
Rui Ueyama 25a6d57b9c Unbreak msan buildbot.
llvm-svn: 275728
2016-07-17 19:55:22 +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 c755599997 Simplify. NFC.
llvm-svn: 275675
2016-07-16 04:19:29 +00:00
Rui Ueyama af469d47e9 Rename SymbolVersions VersionDefinitions.
SymbolVersions sounds like it had versions for a symbol, so rename it.

llvm-svn: 275674
2016-07-16 04:09:27 +00:00
Rui Ueyama f8292e9ac9 ELF: Make check() always return a value.
This patch corresponds to r275511 for COFF.

llvm-svn: 275521
2016-07-15 02:01:03 +00:00
Rui Ueyama aa2db88984 ELF: Make error() to always set HasError.
Previously, it checked for the EC parameter and set HasError
only when there was an error. But in most places we called
error only when error had occurred, so this behavior was confusing.

llvm-svn: 275517
2016-07-15 01:38:54 +00:00
Rui Ueyama 484a49514f Rename VAStart -> ImageBase. NFC.
Config members are named after corresponding command line options.
This patch renames VAStart ImageBase so that they are in line with
--image-base.

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

llvm-svn: 275298
2016-07-13 18:40:59 +00:00
George Rimar bd69903692 [ELF] - Add predefined sections to output sections list in one place.
Minor cleanup.
Currently it looks wierd that having method addPredefinedSections()
we still add 2 sections outside it without real reasons.
Patch fixes that.

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

llvm-svn: 275269
2016-07-13 14:26:31 +00:00
Petr Hosek d7bd2389ce [ELF] Support for setting the base address
The -image-base option allows for overriding the base address.

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

llvm-svn: 275206
2016-07-12 19:37:53 +00:00
George Rimar 6892afaa2d Recommit r275161 "[ELF] - Move section factory out from writer to make it reusable."
With fix:
* fixed compilation error under linux:

template <class ELFT> class OutputSectionFactory {
...
  typedef typename SectionKey<ELFT::Is64Bits> Key;

changed to:
template <class ELFT> class OutputSectionFactory {
...
  typedef typename elf::SectionKey<ELFT::Is64Bits> Key;

llvm-svn: 275166
2016-07-12 09:49:43 +00:00
George Rimar d8f547fab4 Revert r275161 "[ELF] - Move section factory out from writer to make it reusable."
It broke build bot:
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-debian-fast/builds/39652

llvm-svn: 275163
2016-07-12 09:11:13 +00:00
George Rimar 5d53d1f42c [ELF] - Make few members of Writer to be global and export them for reuse
Creating sections on linkerscript side requires some methods
that can be reused if are exported from writer.

Patch implements that change.

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

llvm-svn: 275162
2016-07-12 08:50:42 +00:00
George Rimar e51f7f4d39 [ELF] - Move section factory out from writer to make it reusable.
Since linkerscript should create sections by itself
(if SECTIONS command is present),
then we might want to reuse the OutputSectionFactory (D19976 already do that now),
so this patch moves it out from writer cpp file for that purpose.

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

llvm-svn: 275161
2016-07-12 08:38:04 +00:00
Eugene Leviant eda81a1b86 [ELF] Support for symbol assignment in linker scripts within SECTIONS {} block
llvm-svn: 275158
2016-07-12 06:39:48 +00:00
Rui Ueyama 52c4e17f8a Remove trailing whitespaces.
llvm-svn: 274343
2016-07-01 10:42:25 +00:00
Eugene Leviant 467c4d5538 [ELF] Fix first PT_LOAD segment VA calculation, when linker script is used
llvm-svn: 274342
2016-07-01 10:27:36 +00:00
George Rimar e86dcd0cbd [ELF] - Added support for --unresolved-symbols option.
Option has next description (http://linux.die.net/man/1/ld):
"--unresolved-symbols=method
Determine how to handle unresolved symbols. There are four possible values for method
according to documentation:

ignore-all: Do not report any unresolved symbols.
report-all: Report all unresolved symbols. This is the default.
ignore-in-object-files: Report unresolved symbols that are contained in shared libraries, but ignore them if they come from regular object files.
ignore-in-shared-libs: Report unresolved symbols that come from regular object files, but ignore them if they come from shared libraries."

Since report-all is default and we traditionally do not report about undefined symbols in lld,
report-all does not report about undefines from DSO. 
ignore-in-object-files also does not do that. Handling of that option differs from what gnu linkers do.

Option works in next way in lld:
ignore-all: Do not report any unresolved symbols.
report-all: Report all unresolved symbols except symbols from DSOs. This is the default.
ignore-in-object-files: The same as ignore-all.
gnore-in-shared-libs: The same as report-all.

This is PR24524.

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

llvm-svn: 274123
2016-06-29 12:35:04 +00:00
Rui Ueyama fbbde548cf Move isValidCIdentifier to Strings.cpp.
llvm-svn: 274112
2016-06-29 09:08:02 +00:00
Rui Ueyama 5e64d3fb94 Refactor ELF type inference functions.
Previously, we initialized Config->EKind and Config->EMachine when
we instantiate ELF objects. That was not an ideal location to do that
because the logic was buried too deep inside a concrete logic.

This patch moves the code to the driver so that the initialization
becomes explicit.

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

llvm-svn: 274089
2016-06-29 01:30:50 +00:00
George Rimar d84f21b288 [ELF] - Remove Config->ZDefs flag.
-z defs is the same as --no-undefined (http://linux.die.net/man/1/ld).
It looks to be a error to handle it separatelly.

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

llvm-svn: 274003
2016-06-28 12:04:19 +00:00
George Rimar 602fbee9fc [ELF] - Support of compressed input sections implemented.
Patch implements support of zlib style compressed sections.
SHF_COMPRESSED flag is used to recognize that decompression is required.
After that decompression is performed and flag is removed from output.

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

llvm-svn: 273661
2016-06-24 11:18:44 +00:00
Rui Ueyama 809d8e2d41 Fix a bug that MIPS thunks can overwrite other section contents.
Peter Smith found while trying to support thunk creation for ARM that
LLD sometimes creates broken thunks for MIPS. The cause of the bug is
that we assign file offsets to input sections too early. We need to
create all sections and then assign section offsets because appending
thunks changes file offsets for all following sections.

This patch separates the pass to assign file offsets from thunk
creation pass. This effectively reverts r265673.

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

llvm-svn: 273532
2016-06-23 04:33:42 +00:00
George Rimar d5d544757e [ELF] - Removed excessive reference from pointer arguments. NFC.
llvm-svn: 273155
2016-06-20 13:30:37 +00:00
George Rimar 086fcae95e [ELF] - Forgot to address these two minors before commit r273152. NFC.
llvm-svn: 273154
2016-06-20 13:22:54 +00:00
George Rimar d3566309eb [ELF] - Recommit r273143("[ELF] - Basic versioned symbols support implemented.")
With fix:
-soname flag was not set in testcase. Hash calculated for base def was different on local
and bot machines because filename fos used for calculating.

Initial commit message:
Patch implements basic support of versioned symbols.
There is no wildcards patterns matching except local: *;
There is no support for hierarchies.
There is no support for symbols overrides (@ vs @@ not handled).

This patch allows programs that using simple scripts to link and run.

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

llvm-svn: 273152
2016-06-20 11:55:12 +00:00
George Rimar d03f97211a Revert r273143 "[ELF] - Basic versioned symbols support implemented."
It broke buildbot:
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast

llvm-svn: 273146
2016-06-20 10:29:53 +00:00
George Rimar c31fee2212 [ELF] - Basic versioned symbols support implemented.
Patch implements basic support of versioned symbols.
There is no wildcards patterns matching except local: *;
There is no support for hierarchies.
There is no support for symbols overrides (@ vs @@ not handled).

This patch allows programs that using simple scripts to link and run.

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

llvm-svn: 273143
2016-06-20 10:16:33 +00:00
Rui Ueyama 424b408165 Rename Align -> Alignment.
I think it is me who named these variables, but I always find that
they are slightly confusing because align is a verb.
Adding four letters is worth it.

llvm-svn: 272984
2016-06-17 01:18:46 +00:00
Peter Collingbourne ca8c994818 ELF: Compute used bit for --as-needed during symbol resolution.
We can now use this to decide whether to emit a verneed during the final
pass over the symbols. We were previously wrongly creating a verneed entry
in the case where all references to a DSO's symbols were weak.

In a future change we may also want to use the used bit to control whether
shared symbols are preemptible and appear in the dynsym. This seems a little
tricky to do at the moment because isNeeded() is templated.

The only other functional change here is that we emit a DT_NEEDED for DSOs
whose symbols are all preempted by objects that appear later in the link. But
that doesn't seem too important to me.

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

llvm-svn: 272282
2016-06-09 18:01:35 +00:00
Rui Ueyama 406b469de4 Avoid doing binary search.
MergedInputSection::getOffset is the busiest function in LLD if string
merging is enabled and input files have lots of mergeable sections.
It is usually the case when creating executable with debug info,
so it is pretty common.

The reason why it is slow is because it has to do faily complex
computations. For non-mergeable sections, section contents are
contiguous in output, so in order to compute an output offset,
we only have to add the output section's base address to an input
offset. But for mergeable strings, section contents are split for
merging, so they are not contigous. We've got to do some lookups.

We used to do binary search on the list of section pieces.
It is slow because I think it's hostile to branch prediction.

This patch replaces it with hash table lookup. Seems it's working
pretty well. Below is "perf stat -r10" output when linking clang
with debug info. In this case this patch speeds up about 4%.

Before:

       6584.153205 task-clock (msec)         #    1.001 CPUs utilized            ( +-  0.09% )
               238 context-switches          #    0.036 K/sec                    ( +-  6.59% )
                 0 cpu-migrations            #    0.000 K/sec                    ( +- 50.92% )
         1,067,675 page-faults               #    0.162 M/sec                    ( +-  0.15% )
    18,369,931,470 cycles                    #    2.790 GHz                      ( +-  0.09% )
     9,640,680,143 stalled-cycles-frontend   #   52.48% frontend cycles idle     ( +-  0.18% )
   <not supported> stalled-cycles-backend
    21,206,747,787 instructions              #    1.15  insns per cycle
                                             #    0.45  stalled cycles per insn  ( +-  0.04% )
     3,817,398,032 branches                  #  579.786 M/sec                    ( +-  0.04% )
       132,787,249 branch-misses             #    3.48% of all branches          ( +-  0.02% )

       6.579106511 seconds time elapsed                                          ( +-  0.09% )

After:

       6312.317533 task-clock (msec)         #    1.001 CPUs utilized            ( +-  0.19% )
               221 context-switches          #    0.035 K/sec                    ( +-  4.11% )
                 1 cpu-migrations            #    0.000 K/sec                    ( +- 45.21% )
         1,280,775 page-faults               #    0.203 M/sec                    ( +-  0.37% )
    17,611,539,150 cycles                    #    2.790 GHz                      ( +-  0.19% )
    10,285,148,569 stalled-cycles-frontend   #   58.40% frontend cycles idle     ( +-  0.30% )
   <not supported> stalled-cycles-backend
    18,794,779,900 instructions              #    1.07  insns per cycle
                                             #    0.55  stalled cycles per insn  ( +-  0.03% )
     3,287,450,865 branches                  #  520.799 M/sec                    ( +-  0.03% )
        72,259,605 branch-misses             #    2.20% of all branches          ( +-  0.01% )

       6.307411828 seconds time elapsed                                          ( +-  0.19% )

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

llvm-svn: 270999
2016-05-27 14:39:13 +00:00
Rui Ueyama 0fcdc730ad Create Relocations.cpp and move scanRelocs there.
scanReloc and the functions on which scanReloc depends is in total
more than 600 lines of code. Since scanReloc does not depend on Writer,
it is better to move it into a separate file.

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

llvm-svn: 270606
2016-05-24 20:24:43 +00:00
Rafael Espindola fe3a2f1b81 Revert "Simplify. Thanks to Rui for the suggestion."
This reverts commit r270551.

Sorry, I commited the wrong branch :-(

llvm-svn: 270554
2016-05-24 12:12:06 +00:00
Rafael Espindola dba64b8ea4 Simplify. Thanks to Rui for the suggestion.
llvm-svn: 270551
2016-05-24 11:53:15 +00:00
Rui Ueyama ace4f90cf3 Do not pass the symbol table. NFC.
Since the symbol table is a singleton class and globally accessible,
we don't need to pass it around.

llvm-svn: 270533
2016-05-24 04:25:47 +00:00
Rui Ueyama 0b9a90364b Rename EHInputSection -> EhInputSection.
llvm-svn: 270532
2016-05-24 04:19:20 +00:00
Rui Ueyama 022d8e8a86 Make scanReloc and related functions non-member functions.
scanReloc does not depend on Writer, so it doesn't have to be
in the class.

llvm-svn: 270530
2016-05-24 03:36:07 +00:00
Rui Ueyama afa35a2a37 Remove Writer::ensureBss().
Previously, we created a .bss section when needed. We had a function
ensureBss() for that purpose. Turned out that was error-prone
because it was easy to forget to call that function before accessing
the .bss section.

This patch always make the BSS section. The section is added to the
output when it's not empty.

llvm-svn: 270527
2016-05-24 03:16:51 +00:00
Rui Ueyama 98843087cb Reject zero-sized symbols when creating copy relocations.
Copy relocations are relocations to copy data from DSOs to
executable's .bss segment at runtime. It doesn't make sense to
create such relocations for zero-sized symbols.

GNU linkers don't agree with each other. ld rejects such
relocation/symbol pair. gold don't reject that but do not create
copy relocations as well.  I took the former approach because
I don't think the latter is what user wants.

llvm-svn: 270525
2016-05-24 02:37:40 +00:00
Rui Ueyama 8a6ef4e6b2 Remove dead code.
Since now we always set SHT_PROGBITS to .eh_frame sections,
this code path is not executed at runtime.

llvm-svn: 270446
2016-05-23 16:24:22 +00:00
Rui Ueyama 3b31e6711b Make .eh_frame a singleton output object.
.eh_frame_hdr assumes that there is only one .eh_frame and
ensures it by assertions. This patch makes .eh_frame a real
singleton object to simplify.

llvm-svn: 270445
2016-05-23 16:24:16 +00:00
Rui Ueyama f86cb90a2d Do not propagate section name and attributes to .eh_frame.
.eh_frame is always ".eh_frame" and its attribute is fixed.
No need to copy from inputs to outputs. GNU gold also sets
SHT_PROGBITS.

llvm-svn: 270443
2016-05-23 15:12:41 +00:00
Rui Ueyama 1e479c23aa Rename EHOutputSection -> EhOutputSection for consistency.
llvm-svn: 270442
2016-05-23 15:07:59 +00:00
Rui Ueyama 90fa3722d2 Simplify SplitInputSection::getRangeAndSize.
This patch adds Size member to SectionPiece so that getRangeAndSize
can just return a SectionPiece instead of a std::pair<SectionPiece *, uint_t>.
Also renamed the function.

llvm-svn: 270346
2016-05-22 00:41:38 +00:00
Rui Ueyama 3ea8727188 Define SectionPiece and use it instead of std::pair<uint_t, uint_t>.
We were using std::pair to represents pieces of splittable section
contents. It hurt readability because "first" and "second" are not
meaningful. This patch give them names.

One more thing is that piecewise liveness information is stored to
the second element of the pair as a special value of output section
offset. It was confusing, so I defiend a new bit, "Live", in the
new struct.

llvm-svn: 270340
2016-05-22 00:13:04 +00:00
Rafael Espindola ebed1fe0de Refactor R_RELAX_TLS_* value computation.
This makes it explicit that each R_RELAX_TLS_* is equivalent to some
other expression.

With this I think we are at a sweet spot for how much is done in
Target.cpp. I did experiment with moving *all* the value math out of it.
It has the advantage that we know the final value in target independent
code, but it gets quite verbose.

llvm-svn: 270277
2016-05-20 21:23:52 +00:00
Rafael Espindola 6989ebf661 Simplify, NFC.
llvm-svn: 269983
2016-05-18 21:05:18 +00:00
Rafael Espindola e4c86d83fe Drop vestigial support for UseLazyBinding=false.
Lazy binding is quite important for use case like a shared build of
llvm. Also, if someone wants to disable it, it is better done in the
compiler (disable plt generation).

The only reason to keep it is to make it easier to add a new
architecture. But it doesn't really help much as it is possible to start
with non lazy relocation and plt code but still let the generic part
create a dedicated .got.plt and .rela.plt.

llvm-svn: 269982
2016-05-18 21:03:36 +00:00
Simon Atanasyan 4e3a15c9f3 [ELF][MIPS] Rename R_MIPS_GOT_xxx relocation expression kinds
New names reflect purpose of corresponding GOT entries better.
Both expression types related to entries allocated in the 'local'
part of MIPS GOT. R_MIPS_GOT_LOCAL_PAGE is for entries contain 'page'
addresses. R_MIPS_GOT_LOCAL is for entries contain 'full' address.

llvm-svn: 269597
2016-05-15 18:13:50 +00:00
Rui Ueyama 9194db78fb Support --build-id=0x<hexstring>.
If you specify the option in the form of --build-id=0x<hexstring>,
that hexstring is set as a build ID. We observed that the feature
is actually in use in some builds, so we want this feature.

llvm-svn: 269495
2016-05-13 21:55:56 +00:00