Commit Graph

7352 Commits

Author SHA1 Message Date
Rui Ueyama e5e407beb4 Add comments.
llvm-svn: 288111
2016-11-29 04:17:30 +00:00
Rui Ueyama bd2a812ff0 Print error message header in red.
llvm-svn: 288110
2016-11-29 04:09:08 +00:00
Rafael Espindola f1e245315b Use relocations to fill statically known got entries.
Right now we just remember a SymbolBody for each got entry and
duplicate a bit of logic to decide what value, if any, should be
written for that SymbolBody.

With ARM there will be more complicated values, and it seems better to
just use the relocation code to fill the got entries. This makes it
clear that each entry is filled by the dynamic linker or by the static
linker.

llvm-svn: 288107
2016-11-29 03:45:36 +00:00
Rafael Espindola d3b32df3de Sort. NFC.
llvm-svn: 288102
2016-11-29 03:36:30 +00:00
Rafael Espindola 5498ba38df Add a test.
It would have found a missing case in another patch.

llvm-svn: 288101
2016-11-29 03:30:07 +00:00
George Rimar 1642c5d871 [ELF] - Do not put non exec sections first when -no-rosegment
That unifies handling cases when we have SECTIONS and when
-no-rosegment is given in compareSectionsNonScript()

Now Config->SingleRoRx is used for check, testcase is provided.

llvm-svn: 288022
2016-11-28 10:26:21 +00:00
George Rimar 18a3096282 [ELF] - Set Config->SingleRoRx differently. NFC.
Previously Config->SingleRoRx was set in
createFiles() and used HasSections.

This change moves it to readConfigs at place of
common flags handling, and adds logic that sets
this flag separatelly from ScriptParser if SECTIONS present.

llvm-svn: 288021
2016-11-28 10:11:10 +00:00
George Rimar 63bf011003 [ELF] - Implemented -no-rosegment.
--no-rosegment: Do not put read-only non-executable sections in their own segment

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

llvm-svn: 288020
2016-11-28 10:05:20 +00:00
Eugene Leviant ed30ce7ae4 [ELF] Print file:line for 'undefined section' errors
Differential revision: https://reviews.llvm.org/D27108

llvm-svn: 288019
2016-11-28 09:58:04 +00:00
Rafael Espindola 8e67000f1a Always create a PT_ARM_EXIDX if needed.
Unfortunatelly PT_ARM_EXIDX is special. There is no way to create it
from linker scripts, so we have to create it even if PHDRS is used.

This matches bfd and is required for the lld output to survive bfd's strip.

llvm-svn: 288012
2016-11-28 00:40:21 +00:00
Rui Ueyama 1dd86a664f Add paralell_for and use it where appropriate.
When we iterate over numbers as opposed to iterable elements,
parallel_for fits better than parallel_for_each.

llvm-svn: 288002
2016-11-27 19:28:32 +00:00
Rafael Espindola 5fcc99c27d Also skip regular symbol assignment at the start of a script.
Unfortunatelly some scripts look like

kernphys = ...
. = ....

and the expectation in that every orphan section is after the
assignment.

llvm-svn: 287996
2016-11-27 09:44:45 +00:00
Rafael Espindola 7fe4ec9b3a Don't put an orphan before the first . assignment.
This is an horrible special case, but seems to match bfd's behaviour
and is important for avoiding placing an orphan section before the
expected start of the file.

llvm-svn: 287994
2016-11-27 07:39:45 +00:00
Rui Ueyama e8a077badf Change return types of split{Non,}Strings.
They return new vectors, but at the same time they mutate other vectors,
so returning values doesn't make much sense. We should just mutate two
vectors.

llvm-svn: 287979
2016-11-26 15:15:11 +00:00
Rui Ueyama 72b1ee2533 Make getColorDiagnostics return a boolean value instead of an enum.
Config->ColorDiagnostics was of type enum before. Now it is just a
boolean flag. Thanks Rafael for suggestion.

llvm-svn: 287978
2016-11-26 15:10:01 +00:00
Rui Ueyama 1880bbed39 Split MergeOutputSection::finalize.
llvm-svn: 287977
2016-11-26 15:09:58 +00:00
Rafael Espindola f93b8c29c8 Create sections with just assignments as STT_NOBITS.
This matches the behaviour of bfd ld. Using 0 was causing problems
with strip, which would remove these sections.

llvm-svn: 287969
2016-11-26 06:55:35 +00:00
Davide Italiano 3bfa081aa9 [ELF] Be compliant with LLVM and rename Lto into LTO. NFCI.
llvm-svn: 287967
2016-11-26 05:37:04 +00:00
Rui Ueyama d873e3a694 Fix buildbots.
llvm-svn: 287952
2016-11-25 20:42:39 +00:00
Rui Ueyama 1df9316922 Fix typo.
llvm-svn: 287951
2016-11-25 20:41:45 +00:00
Rui Ueyama c01321c6b8 Do not print out ARGV0 in white because it's unreadable on white background.
llvm-svn: 287950
2016-11-25 20:37:16 +00:00
Rui Ueyama 8c8818a58c Support -color-diagnostics={auto,always,never}.
-color-diagnostics=auto is default because that's the same as
Clang's default. When color is enabled, error or warning messages
are colored like this.

  error:
  <bold>ld.lld</bold> <red>error:</red> foo.o: no such file

  warning:
  <bold>ld.lld</bold> <magenta>warning:</magenta> foo.o: no such file

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

llvm-svn: 287949
2016-11-25 20:27:32 +00:00
Rui Ueyama 6066641423 We shouldn't call parallle_for_each if -no-thread is given.
llvm-svn: 287948
2016-11-25 20:20:57 +00:00
Rui Ueyama 2555952ba8 Parallelize uncompress() and splitIntoPieces().
Uncompressing section contents and spliting mergeable section contents
into smaller chunks are heavy tasks. They scan entire section contents
and do CPU-intensive tasks such as uncompressing zlib-compressed data
or computing a hash value for each section piece.

Luckily, these tasks are independent to each other, so we can do that
in parallel_for_each. The number of input sections is large (as opposed
to the number of output sections), so there's a large parallelism here.

Actually the current design to call uncompress() and splitIntoPieces()
in batch was chosen with doing this in mind. Basically what we need to
do here is to replace `for` with `parallel_for_each`.

It seems this patch improves latency significantly if linked programs
contain debug info (which in turn contain lots of mergeable strings.)
For example, the latency to link Clang (debug build) improved by 20% on
my machine as shown below. Note that ld.gold took 19.2 seconds to do
the same thing.

Before:
    30801.782712 task-clock (msec)         #    3.652 CPUs utilized            ( +-  2.59% )
         104,084 context-switches          #    0.003 M/sec                    ( +-  1.02% )
           5,063 cpu-migrations            #    0.164 K/sec                    ( +- 13.66% )
       2,528,130 page-faults               #    0.082 M/sec                    ( +-  0.47% )
  85,317,809,130 cycles                    #    2.770 GHz                      ( +-  2.62% )
  67,352,463,373 stalled-cycles-frontend   #   78.94% frontend cycles idle     ( +-  3.06% )
 <not supported> stalled-cycles-backend
  44,295,945,493 instructions              #    0.52  insns per cycle
                                           #    1.52  stalled cycles per insn  ( +-  0.44% )
   8,572,384,877 branches                  #  278.308 M/sec                    ( +-  0.66% )
     141,806,726 branch-misses             #    1.65% of all branches          ( +-  0.13% )

     8.433424003 seconds time elapsed                                          ( +-  1.20% )

After:
    35523.764575 task-clock (msec)         #    5.265 CPUs utilized            ( +-  2.67% )
         159,107 context-switches          #    0.004 M/sec                    ( +-  0.48% )
           8,123 cpu-migrations            #    0.229 K/sec                    ( +- 23.34% )
       2,372,483 page-faults               #    0.067 M/sec                    ( +-  0.36% )
  98,395,342,152 cycles                    #    2.770 GHz                      ( +-  2.62% )
  79,294,670,125 stalled-cycles-frontend   #   80.59% frontend cycles idle     ( +-  3.03% )
 <not supported> stalled-cycles-backend
  46,274,151,813 instructions              #    0.47  insns per cycle
                                           #    1.71  stalled cycles per insn  ( +-  0.47% )
   8,987,621,670 branches                  #  253.003 M/sec                    ( +-  0.60% )
     148,900,624 branch-misses             #    1.66% of all branches          ( +-  0.27% )

     6.747548004 seconds time elapsed                                          ( +-  0.40% )

llvm-svn: 287946
2016-11-25 20:05:08 +00:00
Rui Ueyama 623b36e358 Move typedefs inside a class definition.
llvm-svn: 287945
2016-11-25 18:51:56 +00:00
Rui Ueyama 22375f2406 Remove a parameter from ScriptParser.
llvm-svn: 287944
2016-11-25 18:51:54 +00:00
Rui Ueyama da06bfb794 Move getLocation from Relocations.cpp to InputSection.cpp.
The function was used only within Relocations.cpp, but now we are
using it in many places, so this patch moves it to a file that fits
to the functionality.

llvm-svn: 287943
2016-11-25 18:51:53 +00:00
Eugene Leviant f04777527e [ELF] Add explicit template instantiations for toString
llvm-svn: 287938
2016-11-25 16:42:04 +00:00
Eugene Leviant ab024a353f [ELF] Refactor getDynRel to print error location
Differential revision: https://reviews.llvm.org/D27055

llvm-svn: 287915
2016-11-25 08:56:36 +00:00
Eugene Leviant c8c1b7bfae [ELF] EhOutputSection improvements
Differential revision: https://reviews.llvm.org/D27098

llvm-svn: 287914
2016-11-25 08:27:15 +00:00
George Rimar 11992c86d9 [ELF] - Add support for access to most of synthetic sections from linkerscript.
This is important for cases like:

  .sdata        : {
    *(.got.plt .got)
...
  }

That was not supported before as there was no way to get access to 
synthetic sections from script.

More details on review page.

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

llvm-svn: 287913
2016-11-25 08:05:41 +00:00
Rui Ueyama 26081caf48 Use toString() to report incompatible files.
llvm-svn: 287901
2016-11-24 20:59:44 +00:00
Rui Ueyama d4c94d1899 Include a hint how to see all errors if error is truncated.
This patch changes the error message from

  too many errors emitted, stopping now

to

  too many errors emitted, stopping now (use -error-limit=0 to see all errors)

Thanks for Sean for the suggestion!

llvm-svn: 287900
2016-11-24 20:31:43 +00:00
Rui Ueyama a3ac17372b Define toString(const SymbolBody &) and remove maybeDemangle instead.
Differential Revision: https://reviews.llvm.org/D27065

llvm-svn: 287899
2016-11-24 20:24:18 +00:00
Rafael Espindola 4862ae8cc5 Use a more explicit type for the sizeof.
llvm-svn: 287895
2016-11-24 16:38:35 +00:00
Peter Smith 719eb8efa5 [ELF] Add terminating sentinel .ARM.exidx table entry
The .ARM.exidx table has an entry for each function with the first entry
giving the start address of the function, the table is sorted in ascending
order of function address. Given a PC value, the unwinder will search the
table for the entry that contains the PC value.
    
If the table entry happens to be the last, the range of the addresses that
the final unwinding table describes will extend to the end of the address
space. To prevent an incorrect address outside the address range of the
program matching the last entry we follow ld.bfd's example and add a
sentinel EXIDX_CANTUNWIND entry at the end of the table. This gives the
final real table entry an upper bound.
    
In addition the llvm libunwind unwinder currently depends on the presence
of a sentinel entry (PR31091).

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

llvm-svn: 287869
2016-11-24 11:43:55 +00:00
George Rimar 066bf6e1b3 [ELF] - Removed unused method. NFC.
llvm-svn: 287860
2016-11-24 09:42:10 +00:00
Rui Ueyama 3aaacb282f Update comment.
llvm-svn: 287850
2016-11-24 01:44:21 +00:00
Rui Ueyama f373dd76ce Remove HasError and use ErrorCount instead.
HasError was always true if ErrorCount > 0, so we can use ErrorCount instead.

llvm-svn: 287849
2016-11-24 01:43:21 +00:00
Rui Ueyama bf9523f549 [COFF] Add DebugInfoCodeView dependency
rL287555 introduces a link error when building with BUILD_SHARED_LIBS:

  undefined reference to llvm::codeview::CVSymbolDumper::dump(),
  and more...

The functions are available in libDebugInfoCodeView, from LLVM.

Patch by Visoiu Mistrih Francis!

llvm-svn: 287837
2016-11-23 22:58:25 +00:00
Rui Ueyama 2eda6d1633 Set default entry point to .text if no entry point is found.
Previously, if a symbol specified by -e or ENTRY() is not found,
we didn't set entry point address. That is incompatible with GNU
because GNU linkers set the first address of .text to entry.
This patch implement that behavior.

llvm-svn: 287836
2016-11-23 22:41:00 +00:00
Simon Atanasyan 8469b8841c [ELF][MIPS] Fix handling of _gp/_gp_disp/__gnu_local_gp symbols
Offset between beginning of a .got section and _gp symbols used in MIPS
GOT relocations calculations. Usually the expression looks like
VA + Offset - GP, where VA is the .got section address, Offset - offset
of the GOT entry, GP - offset between .got and _gp. Also there two "magic"
symbols _gp_disp and __gnu_local_gp which hold the offset mentioned above.
These symbols might be referenced by MIPS relocations.

Now the linker always defines _gp symbol and uses hardcoded value for
its initialization. So offset between .got and _gp is 0x7ff0. The _gp_disp
and __gnu_local_gp defined if required and initialized by 0x7ff0.
In fact that is not correct because _gp symbol might be defined by a linker
script and holds arbitrary value. In that case we need to use this value
in relocation calculation and initialize _gp_disp and __gnu_local_gp
properly.

The patch fixes the problem and completes fixing the bug #30311.
https://llvm.org/bugs/show_bug.cgi?id=30311

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

llvm-svn: 287832
2016-11-23 22:22:16 +00:00
Rui Ueyama 835bd72322 Remove trailing whitespace.
llvm-svn: 287830
2016-11-23 22:10:46 +00:00
Rui Ueyama d3a06ffb1c Use llvm::utohexstr instead of Twine::utohexstr.
They are essentially the same in this context, so I prefer the one
that doesn't need `Twine::`.

llvm-svn: 287814
2016-11-23 21:24:26 +00:00
Rafael Espindola 20b6d3d0d3 Fix this on 32 bit hosts.
Looks like we have no 32 bit bot that builds with mips support.

llvm-svn: 287799
2016-11-23 19:16:20 +00:00
Rui Ueyama 1b591cf3d3 Fix uninitialized variable access.
llvm-svn: 287797
2016-11-23 19:03:35 +00:00
Rui Ueyama 0ede7f281e Make log(), error() and fatal() thread-safe.
llvm-svn: 287794
2016-11-23 18:34:28 +00:00
Rui Ueyama ac95f6bfcc Limit default maximum number of errors to 20.
This is in the context of https://llvm.org/bugs/show_bug.cgi?id=31109.
When LLD prints out errors for relocations, it tends to print out
extremely large number of errors (like millions) because it would
print out one error per relocation.

This patch makes LLD bail out if it prints out more than 20 errors.
You can configure the limitation using -error-limit argument.
-error-limit=0 means no limit.

I chose the flag name because Clang has the same feature as -ferror-limit.
"f" doesn't make sense to us, so I omitted it.

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

llvm-svn: 287789
2016-11-23 18:15:37 +00:00
Rui Ueyama 28590b6118 Re-commit r287727: Use SHA1::hash and MD5::hash functions.
r287727 was not a change that broke buildbots; the other change
(r287726) that I made to LLVM broke them.

llvm-svn: 287788
2016-11-23 18:11:38 +00:00
Rui Ueyama 3fc0f7e54f Define toString() as a generic function to get a string for error message.
We have different functions to stringize objects to construct
error messages. For InputFile, we have getFilename, and for
InputSection, we have getName. You had to memorize them.

I think this is the case where the function overloading comes in handy.

This patch defines toString() functions that are overloaded for all these
types, so that you just call it in error().

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

llvm-svn: 287787
2016-11-23 18:07:33 +00:00