Commit Graph

481 Commits

Author SHA1 Message Date
George Rimar 2bb88ab5e0 [ELF] - Implemented --retain-symbols-file option
--retain-symbols-file=filename
Retain only the symbols listed in the file filename, discarding all others. 
filename is simply a flat file, with one symbol name per line. This option 
is especially useful in environments (such as VxWorks) where a large global 
symbol table is accumulated gradually, to conserve run-time memory.

Note: though documentation says "--retain-symbols-file does not discard 
undefined symbols, or symbols needed for relocations.", both bfd and gold 
do that, and this patch too, like testcase show.

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

llvm-svn: 290122
2016-12-19 18:00:52 +00:00
Rui Ueyama 8f687f71fb Remove inappropriate use of CachedHashStringRef.
Use of CachedHashStringRef makes sense only when we reuse hash values.
Sprinkling it to all DenseMap has no benefits and just complicates data types.
Basically we shouldn't use CachedHashStringRef unless there is a strong
reason to to do so.

llvm-svn: 290076
2016-12-19 03:14:16 +00:00
Rui Ueyama 9381eb1045 Remove lld/Support/Memory.h.
I thought for a while about how to remove it, but it looks like we
can just copy the file for now. Of course I'm not happy about that,
but it's just less than 50 lines of code, and we already have
duplicate code in Error.h and some other places. I want to solve
them all at once later.

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

llvm-svn: 290062
2016-12-18 14:06:06 +00:00
Rui Ueyama 3c04f8d790 Print a warning message if ENTRY() symbol is not found.
llvm-svn: 289146
2016-12-08 22:26:31 +00:00
Rui Ueyama 520d9169e6 Move Memory.{h,cpp} to lld/Support so that we can use them from COFF.
llvm-svn: 289084
2016-12-08 18:31:13 +00:00
Rafael Espindola d0ebd84c42 Change the implementation of --dynamic-list to use linker script parsing.
The feature is documented as
-----------------------------
The format of the dynamic list is the same as the version node
without scope and node name.  See *note VERSION:: for more
information.
--------------------------------

And indeed qt uses a dynamic list with an 'extern "C++"' in it. With
this patch we support that

The change to gc-sections-shared makes us match bfd. Just because we
kept bar doesn't mean it has to be in the dynamic symbol table.

The changes to invalid-dynamic-list.test and reproduce.s are because
of the new parser.

The changes to version-script.s are the only case where we change
behavior with regards to bfd, but I would like to see a mix of
--version-script and --dynamic-list used in the wild before
complicating the code.

llvm-svn: 289082
2016-12-08 17:54:26 +00:00
Rui Ueyama 6f6d46d497 Use `make` to simplify. NFC.
llvm-svn: 289081
2016-12-08 17:48:52 +00:00
Rui Ueyama 6dbf7ff747 Use make to instantiate Target and LinkerScript. NFC.
llvm-svn: 289079
2016-12-08 17:44:39 +00:00
Rui Ueyama e4eadb6a24 Split LinkerDriver::link. NFC.
llvm-svn: 289078
2016-12-08 17:44:37 +00:00
Rui Ueyama 34bf8677a4 Remove a special handling of AMDGPU entry points.
This is the last peculiar semantics left in the linker. If you want to
always set an entry point to 0, you can pass `-e 0` to the linker.

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

llvm-svn: 289077
2016-12-08 17:32:58 +00:00
Rafael Espindola d4db0b3748 Rename MaxPageSize to DefaultMaxPageSize to avoid confusion.
Thanks to Rui for the suggestion.

llvm-svn: 288982
2016-12-07 21:13:27 +00:00
Rafael Espindola 476d20764a Use the correct MaxPageSize.
Now Target->MaxPageSize is only used as the default value of
Config->MaxPageSize.

llvm-svn: 288974
2016-12-07 20:29:46 +00:00
Rui Ueyama 4de746f326 Add comments and reorder code a bit to clarify the intention. NFC.
llvm-svn: 288885
2016-12-07 04:45:34 +00:00
Rui Ueyama 9e5f5effe5 Make a decision about whether we should warn on missing entry or not early.
Config->WarnMissingEntry is a single-purpose boolean variable, and
I think it's easier to understand than Config->HasEntry.

llvm-svn: 288883
2016-12-07 04:06:21 +00:00
Rui Ueyama a1407c4fdf Simplify -e <number> option handling.
This patch is to parse the entry symbol name lazily.

llvm-svn: 288882
2016-12-07 03:23:06 +00:00
Petr Hosek 2f50fef095 [ELF] Shared libraries should have entry point
Shared libraries should have entry set following the same rules as for
regular binaries. The only difference is that in case the default entry
point (_start or __start) isn't found (unless it was set explicitly), we
shouldn't give a warning as in case of regular binaries.

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

llvm-svn: 288878
2016-12-07 02:26:16 +00:00
Rafael Espindola 61d052d725 Don't discard .L symbol with -r.
They might be used by relocations.

Fixes pr31252.

llvm-svn: 288617
2016-12-04 08:34:17 +00:00
Rui Ueyama 244a435ae3 Factor out common code to a header.
llvm-svn: 288599
2016-12-03 21:24:51 +00:00
George Rimar d250618c3e [ELF] - Disable relro when -omagic specified.
--omagic is an option to create old-fashioned executables in which
.text segments are writable. Today, the option is still in use to
create special-purpose programs such as boot loaders. It doesn't
make sense to create PT_GNU_RELRO for such executables.

DIfferential revision: https://reviews.llvm.org/D27297

llvm-svn: 288579
2016-12-03 07:09:28 +00:00
Simon Atanasyan 9705ff74ed [ELF][MIPS] Restore Config->Threads for MIPS targets
llvm-svn: 288130
2016-11-29 10:24:00 +00:00
George Rimar 595a763f38 [ELF] - Implemented -N (-omagic) command line option.
-N (-omagic)
  Set the text and data sections to be readable and writable. 
  Also, do not page-align the data segment.

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

llvm-svn: 288123
2016-11-29 09:43:51 +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
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
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 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 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 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
Simon Atanasyan 399ac5c3fb [ELF][MIPS] Turn Config->Threads off for MIPS targets
For now MipsGotSection class is not ready for concurrent access from
multiple threads. The problem is in the getPageEntryOffset method. It
changes state of MipsGotSection object and might be called from
different threads at the same time. So turn Threads off for this target.

It's a temporary solution. The patch fixes MipsGotSection::getPageEntryOffset
is almost ready.

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

llvm-svn: 287740
2016-11-23 05:25:02 +00:00
Eugene Leviant 7d7ff80f4b [ELF] Better error reporting for broken archives
Differential revision: https://reviews.llvm.org/D26852

llvm-svn: 287527
2016-11-21 09:28:07 +00:00
Rui Ueyama f7dfb2e250 Remove a file that is too short to be an independent file.
We have a .cpp and a .h for parseDynamicList(). This patch
moves the function to DriverUtil.cpp.

llvm-svn: 287468
2016-11-19 23:26:41 +00:00
Rui Ueyama 061f9286df Use Optional<std::string> instead of "" to represent a failure.
llvm-svn: 287456
2016-11-19 19:23:58 +00:00
George Rimar 0a94bffe12 [ELF] - Exit on --version call.
GNU linkers disagree here.
Though both -version and -v are mentioned
in help to print the version information, GNU ld just normally exits,
while gold can continue linking. We are compatible with ld.bfd here.

This fixes PR31057.

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

llvm-svn: 287448
2016-11-19 18:14:24 +00:00
Rui Ueyama 7ee38e00a5 Enable -threads by default.
LLD supports multi-threading, and it seems to be working well as
you can see in r287140. In short, LLD runs a few percent to 30%
faster with -threads and more than 50% faster if you are using
-build-id (your mileage may vary depending on your computer).

However, I don't think most users even don't know about that because
-threads is not a default option.

This patch enables it by default.

Discussion thread:
http://lists.llvm.org/pipermail/llvm-dev/2016-November/107160.html

llvm-svn: 287237
2016-11-17 17:06:51 +00:00
Rui Ueyama cb87675186 Define -build-id=tree as a synonym for -build-id=sha1.
Our build-id is a tree hash anyway, so I'll define this as a synonym
for sha1. GNU gold takes this parameter, so this is for compatibility
with that.

llvm-svn: 287119
2016-11-16 17:14:11 +00:00
Rui Ueyama 23f441d3ac Add -no-threads option that negates the effect of -threads.
llvm-svn: 287072
2016-11-16 01:39:50 +00:00
Peter Collingbourne cd513a41c1 Bitcode: Clean up error handling for certain bitcode query functions.
The functions getBitcodeTargetTriple(), isBitcodeContainingObjCCategory(),
getBitcodeProducerString() and hasGlobalValueSummary() now return errors
via their return value rather than via the diagnostic handler.

To make this work, re-implement these functions using non-member functions
so that they can be used without the LLVMContext required by BitcodeReader.

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

llvm-svn: 286623
2016-11-11 19:50:24 +00:00
Mehdi Amini 41af43092c Make the Error class constructor protected
This is forcing to use Error::success(), which is in a wide majority
of cases a lot more readable.

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

llvm-svn: 286561
2016-11-11 04:28:40 +00:00
Rui Ueyama 049e045c3a Handle Archive::children's error proerly.
The previous code didn't make sense at all. Now an error condition
is handled with fatal(). Thanks to Mehdi for pointing out the issue.

llvm-svn: 286547
2016-11-11 02:09:28 +00:00
George Rimar 1a33c0f242 [ELF] - Implemented --symbol-ordering-file option.
Patch allows to pass a symbols file to linker.
LLD will map symbols to sections and sort sections
in output according to symbol ordering file.

That can help to reduce the startup time and/or
amount of pagefaults during startup.

Also, interesting benchmark result was produced by Rafael Espíndola. 
After applying the symbols file for clang he timed compiling 
X86MCTargetDesc.ii to an object file.  

The page faults went from just
56,988 to 56,946 since most faults are not in the binary.
Running time went from 4.403053515 to 4.178112244. 
The speedup seems to be because of better cache
locality.

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

llvm-svn: 286440
2016-11-10 09:05:20 +00:00
Rui Ueyama 58026af7f0 Simplify parseEmulation. NFC.
llvm-svn: 286406
2016-11-09 22:32:43 +00:00
Rafael Espindola 8f9026baff Don't add null and discarded sections to the global list.
Avoids having to skip them multiple times.

llvm-svn: 286261
2016-11-08 18:23:02 +00:00
Simon Atanasyan 9e0297b8bc [ELF][MIPS] N32 ABI support
In short the patch introduces support for linking object file conform
MIPS N32 ABI [1]. This ABI is similar to N64 ABI but uses 32-bit
pointer size.

The most non-trivial requirement of this ABI is one more relocation
packing format. N64 ABI puts multiple relocation type into the single
relocation record. The N32 ABI uses series of successive relocations
with the same offset for this purpose. In this patch, new function
`mergeMipsN32RelTypes` handle this case and "convert" N32 relocation to
the N64 relocation so the rest of the code keep unchanged.

For now, linker does not support series of relocations applied to sections
without SHF_ALLOC bit. Probably later I will add the support or insert
some sort of assert into the `relocateNonAlloc` routine to catch this
case.

[1] ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/MIPS-N32-ABI-Handbook.pdf

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

llvm-svn: 286052
2016-11-05 22:58:01 +00:00
Rui Ueyama 8c6a5aaf15 Create a vector containing all input sections.
Previously, we do this piece of code to iterate over all input sections.

  for (elf::ObjectFile<ELFT> *F : Symtab.getObjectFiles())
    for (InputSectionBase<ELFT> *S : F->getSections())

It turned out that this mechanisms doesn't work well with synthetic
input sections because synthetic input sections don't belong to any
input file.

This patch defines a vector that contains all input sections including
synthetic ones.

llvm-svn: 286051
2016-11-05 22:37:59 +00:00
Rui Ueyama d52adb3917 Provide a convenient function to allocate and initialize objects.
You can now write make<T>(Args) instead of new (alloc<T>()) T(Args).

llvm-svn: 285760
2016-11-01 22:53:18 +00:00
Rafael Espindola 5c9e8f5e52 Replace GAlloc with a template function.
This patch replaces GAlloc<ELFT>::<sometype>.Allocate() with
alloc<sometype<ELFT>>().

Patch by Rui!

llvm-svn: 285748
2016-11-01 21:06:40 +00:00
Rui Ueyama 55518e7dd8 Consolidate BumpPtrAllocators.
Previously, we have a lot of BumpPtrAllocators, but all these
allocators virtually have the same lifetime because they are
not freed until the linker finishes its job. This patch aggregates
them into a single allocator.

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

llvm-svn: 285452
2016-10-28 20:57:25 +00:00
Rafael Espindola 7cc713adcb Store OSABI in Config.
This allows us to set a value for it based on -m.

llvm-svn: 285294
2016-10-27 14:00:51 +00:00
Rafael Espindola cb09daab0a Call _exit.
As the state of lld gets more complicated, shutting down gets more
expensive.

In a normal lld run we can just call _exit immediately after renaming
the temporary output file. We still want the ability to run a full
shutdown since that is useful for detecting memory leaks.

This patch adds a --full-shutdown flag and changes lit to use it.

llvm-svn: 285224
2016-10-26 18:59:00 +00:00
Rafael Espindola 5da1d88492 Reduce the number of allocators.
We used to have one allocator per file, which reduces the advantage of
using an allocator in the first place.

This is a small speed up is most cases. The largest speedup was in
1.014X in chromium no-gc. The largest slowdown was scylla at 1.003X.

llvm-svn: 285205
2016-10-26 15:34:24 +00:00
Rui Ueyama c5dd543d8b Split LinkerDriver::link. NFC.
llvm-svn: 285169
2016-10-26 04:34:16 +00:00
Rui Ueyama c773c9f491 Rename variable to be more consistent.
llvm-svn: 285164
2016-10-26 04:01:07 +00:00
Rui Ueyama 80695c1aef Truncate a SVN path part from --version output.
This is in sync with what clang does.

llvm-svn: 285163
2016-10-26 03:52:06 +00:00
George Rimar 58fa5243cc [ELF] - Partial support of --gdb-index command line option (Part 1).
In this patch partial gdb_index section is created. 
For costructing the .gdb_index section 6 steps should be performed (details are in
SplitDebugInfo.cpp file header), this patch do first 3:

Creates proper section header.
Fills list of compilation units.
Types CU list area is not supposed to be supported, so it is ignored and therefore
can be treated as implemented either.

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

llvm-svn: 284708
2016-10-20 09:19:48 +00:00
George Rimar a4c7e74d4b [ELF] - Applied clang format. NFC.
llvm-svn: 284705
2016-10-20 08:36:42 +00:00
Rui Ueyama 388838ed23 Format. NFC.
llvm-svn: 284697
2016-10-20 05:23:23 +00:00
Rui Ueyama c3d15128de Remove Config::Binary.
This member is used only by LinkerDriver, so move it to LinkerDriver.

llvm-svn: 284696
2016-10-20 05:12:29 +00:00
Rui Ueyama d6877631d6 Remove an optional parameter from LinkerDriver::addFile to simplify.
llvm-svn: 284695
2016-10-20 05:03:49 +00:00
Rui Ueyama c185c0122f Split LinkerDriver::createFiles. NFC.
llvm-svn: 284694
2016-10-20 04:47:47 +00:00
Rui Ueyama d7c4454fb2 Fix error message for unknown -format argument.
-format=<foo>, -format <foo> and -b <foo> are all the same.
Previous code was intended to produce an error message with the
same spelling as given from the command line, but it actually
always printed out this string: "unknown -format= value:".
This is probably more confusing than "unknown -format value:".
So I changed the message.

llvm-svn: 284693
2016-10-20 04:47:45 +00:00
Rui Ueyama 0aeb1199ea Simplify. NFC.
llvm-svn: 284692
2016-10-20 04:36:36 +00:00
Rui Ueyama 8da7aa0894 Allow linker-script-defined entry symbols.
Previously, we were checking the existence of an entry symbol
too early. It was done before the linker script processor creates
symbols defined in scripts. Fixes bug 30743.

llvm-svn: 284676
2016-10-20 00:07:36 +00:00
Rui Ueyama 4ff3b5adc3 Move getVersionString to Core and simplify Version.cpp.
llvm-svn: 284641
2016-10-19 20:53:07 +00:00
Rui Ueyama 22646a80f4 Include ARGV[0] in error messages.
This is what other linkers and clang driver do.

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

llvm-svn: 284634
2016-10-19 20:05:43 +00:00
Rui Ueyama 8088ebe499 Remove ending "." from an error message.
Other error messages don't end with ".".

llvm-svn: 284625
2016-10-19 18:09:52 +00:00
Peter Smith 9bbd4e27a9 [ELF] Support for R_ARM_TARGET2 relocation
The R_ARM_TARGET2 relocation is used in ARM exception tables to encode
a data dependency that will only be dereferenced by code in the
run-time support library. In a similar way to R_ARM_TARGET1 the
handling of the relocation is target specific, it maps to one of
R_ARM_ABS32, R_ARM_REL32 or R_ARM_GOT_PREL. The choice depends on the 
run-time library. R_ARM_GOT_PREL is used for linux and BSD,
R_ARM_ABS32 and R_ARM_REL32 are used for bare-metal.

The command line option --target2=<target> can be used to select the
relocation used for R_ARM_TARGET2. The default is R_ARM_GOT_PREL.

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

llvm-svn: 284404
2016-10-17 18:12:24 +00:00
George Rimar c3c4f46d07 [ELF] - Add support for -nopie
This is https://llvm.org/bugs/show_bug.cgi?id=30696,

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

llvm-svn: 284388
2016-10-17 14:42:11 +00:00
George Rimar cc6e567ca3 [ELF] - Implemented -z wxneeded.
-z wxneeded creates a PHDR PT_OPENBSD_WXNEEDED.

PT_OPENBSD_WXNEEDED
The array element specifies that a process executing this file may need to be able to map or protect memory regions as simultaneously executable and writable. If the system is unable or unwilling to permit that for this executable then it may fail immediately. This segment type is meaningful only for executable files and is ignored in other objects.

http://man.openbsd.org/OpenBSD-current/man5/elf.5

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

llvm-svn: 284226
2016-10-14 10:34:36 +00:00
Rui Ueyama 110dda7915 Make variable name consistent with other -z options.
llvm-svn: 283910
2016-10-11 17:46:48 +00:00
Davide Italiano b6e6e4a074 [LTO] Split the options for ThinLTO jobs and Regular LTO partitions
Differential Revision:   https://reviews.llvm.org/D25452

llvm-svn: 283817
2016-10-10 23:12:14 +00:00
Rui Ueyama c79ecdd876 Use StringSwtich::Cases for multiple choices.
llvm-svn: 282964
2016-09-30 22:01:25 +00:00
Rui Ueyama d31e13f287 Rename warning -> warn.
It's better because it's a verb.

llvm-svn: 282763
2016-09-29 21:00:23 +00:00
Petr Hosek 997f8838e5 [ELF] Support -z max-page-size option
This options issupported by both BFD ld and gold and allows
overriding the max page size whose default values are defined by
the target.

https://llvm.org/bugs/show_bug.cgi?id=30541

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

llvm-svn: 282596
2016-09-28 15:20:47 +00:00
Petr Hosek 5d98fef75d [ELF] Use MaxPageSize for aligning PT_LOAD
This matches the behavior of Binutils linkers. We also change the
default MaxPageSize on x86-64 to 0x1000 to preserver the current
behavior, which is the same as the behavior implemented by gold.

https://llvm.org/bugs/show_bug.cgi?id=30541

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

llvm-svn: 282560
2016-09-28 00:09:20 +00:00
George Rimar a213e6b6f5 [ELF] - Fix for: Bug 30521 - lld exits non-zero return value linking a library with no entry symbol
PR30521 was about linking shared library. After r282295 code when linking -shared produced
"entry symbol not found" warning, what in combination with --fatal-errors failed linkage.

Patch fixes logic (and adds testcases) to follow next rules:

1) If entry was specified and not found report warning.
2) If entry was not specified then:
 a) Emit warning if not -shared.
 b) Do not emit warning if -shared.

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

llvm-svn: 282427
2016-09-26 19:04:42 +00:00
Rafael Espindola 251e240adc Warn if we can't find the entry symbol.
Fixes pr30465.

llvm-svn: 282295
2016-09-23 21:04:56 +00:00
Rafael Espindola db62cbb97f Don't produce an error for undefined entry symbol.
This is particularly important when the symbol comes from a linker
script. It is common to use the same linker script for shared
libraries and executables. Without this we would always fail to link
shared libraries with -z,defs and a linker script with an ENTRY
directive.

llvm-svn: 281989
2016-09-20 17:14:16 +00:00
Rui Ueyama b2a0abdf0e Rename SortSectionPolicy::IgnoreConfig to None.
Because it corresponds to SORT_NONE. None was renamed Default.

llvm-svn: 281776
2016-09-16 21:14:55 +00:00
George Rimar be394db376 [ELF] - Implemented --sort-section cmd line option and SORT_NONE script command.
This fixes Bug 30385 - SORT_NONE not implemented,

`SORT_NONE' disables section sorting by ignoring the command line
section sorting option.

That is why this patch also implements --sort-section option.

Description of sorting rules
available at https://sourceware.org/binutils/docs/ld/Input-Section-Wildcards.html 

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

llvm-svn: 281771
2016-09-16 20:21:55 +00:00
George Rimar d73ef1738b [ELF] - Implemented --section-start, -Ttext, -Tdata, -Tbss options.
--section-start=sectionname=org
Locate a section in the output file at the absolute address given by org. 
You may use this option as many times as necessary to locate multiple sections in the command line.
 org must be a single hexadecimal integer; for compatibility with other linkers, 
you may omit the leading `0x' usually associated with hexadecimal values. 
Note: there should be no white space between sectionname, the equals sign (“<=>”), and org.

-Tbss=org
-Tdata=org
-Ttext=org
Same as --section-start, with .bss, .data or .text as the sectionname.

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

llvm-svn: 281458
2016-09-14 13:07:13 +00:00
Rafael Espindola d88d7166a8 Use murmurhash2 instead of fnv.
It is substantially faster by processing 8 bytes at a time.

llvm-svn: 281454
2016-09-14 11:32:57 +00:00
Rui Ueyama 38dbd3eea9 Simplify InputFile ownership management.
Previously, all input files were owned by the symbol table.
Files were created at various places, such as the Driver, the lazy
symbols, or the bitcode compiler, and the ownership of new files
was transferred to the symbol table using std::unique_ptr.
All input files were then free'd when the symbol table is freed
which is on program exit.

I think we don't have to transfer ownership just to free all
instance at once on exit.

In this patch, all instances are automatically collected to a
vector and freed on exit. In this way, we no longer have to
use std::unique_ptr.

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

llvm-svn: 281425
2016-09-14 00:05:51 +00:00
Rui Ueyama a75b7a48f1 Fix comments.
llvm-svn: 281380
2016-09-13 19:56:25 +00:00
Michael J. Spencer a9424f39c4 [ELF] Add support for -b binary
Implemented by building an ELF file in memory.

elf, default, and binary match gold behavior.

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

llvm-svn: 281108
2016-09-09 22:08:04 +00:00
Ed Maste e349b6da2c ELF: clarify error when we don't know the output format
lld differs from GNU ld in that it does not have a built-in default
target emulation. Emulation is always specified via the -m option, or
obtained from the object file(s) being linked. In most cases at least
one ELF object is included in the link, so the emulation is known.

When using lld's (not yet committed) -b binary support with -r, to
convert a binary file into an ELF object we do not have a known
emulation. The error message previously emitted in this case
"-m or at least a .o file required" is accurate but does not offer
much insight. Add text to the error message to give a hint why -m or an
object file is required.

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

llvm-svn: 280989
2016-09-08 21:06:29 +00:00
Ed Maste 2b68ada188 ELF: Report original emulation name in "unknown emulation" error
A trailing _fbsd is stripped from emulation names, but if the result was
still not a valid emulation the error was somewhat confusing.

For example,

% ld.lld -m elf_amd64_fbsd
unknown emulation: elf_amd64

Use the original emulation name in error messages.

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

llvm-svn: 280983
2016-09-08 19:36:22 +00:00
Ed Maste 21e2be6403 ELF: accept -m elf_amd64 as an alias for -m elf_x86_64
In the FreeBSD world x86_64 still has its original name, amd64. Accept
it as an alias.

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

llvm-svn: 280982
2016-09-08 19:30:47 +00:00
Eugene Leviant 3967ea05a9 Set entry address to 0x0 if no _start symbol
Differential revision: https://reviews.llvm.org/D23925

llvm-svn: 280912
2016-09-08 08:57:51 +00:00
George Rimar 884e786d38 [ELF] - Linkerscript: simplify access to templated methods from parser.
Previous way of accessing templated methods was a bit bulky,
Patch introduces small interface based solution.

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

llvm-svn: 280910
2016-09-08 08:19:13 +00:00
Petr Hosek 5baa1c7641 [ELF] Add support for -no-gc-sections flag
This flag is supported by both BFD ld and gold and is occasionally
used to negate the effect of -gc-sections flag.

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

llvm-svn: 280729
2016-09-06 18:28:49 +00:00
Rui Ueyama 6af4016f6d Simplify. NFC.
llvm-svn: 280533
2016-09-02 19:49:27 +00:00
Rui Ueyama fee70ea8c6 Rename UnresolvedPolicy::Error -> UnresolvedPolicy::ReportError.
"Error" looks like it is indicating a parse error. "Error" actually
instructs the later process to report an error if there's an error
condition. Thus the new name.

llvm-svn: 280529
2016-09-02 19:36:29 +00:00
Rui Ueyama 6c7ad13f89 Add -nostdlib.
llvm-svn: 280528
2016-09-02 19:20:33 +00:00
George Rimar b952ece2df [ELF] - Fix for: bug 30237 - lld does not implement -f option
FreeBSD's libstdc++ build (used on tier-2 architectures) uses GNU ld's 
-f <name> option, which sets the DT_AUXILIARY field to the specified name.
Multiple -f options may be specified and the DT_AUXILIARY entries 
will be added in the order in which they appear.

Patch implements that option.

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

llvm-svn: 280475
2016-09-02 09:13:05 +00:00
George Rimar 20b6598c10 [ELF] - Remove VersionScriptParser class and move the members to ScriptParser
Patch removes VersionScriptParser class and moves the members to ScriptParser
It opens road for implementation of VERSION linkerscript command.

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

llvm-svn: 280212
2016-08-31 09:08:26 +00:00
George Rimar ebf1da565c [ELF] - Fix (partial) for bug 28843 - Make sure we handle options with opposing meanings.
As stated in PR28843:

we should handle command lines with

-target1-rel -target1-abs
--demangle --no-demangle
Patch implements this for specified options.
There are probably other conflicting options can exist,
so fix is called "partial".

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

llvm-svn: 280211
2016-08-31 08:53:21 +00:00
George Rimar 9503f6d211 [ELF] - Introduce DiscardPolicy instead of 3 relative bool fields.
DiscardPolicy is enum replacing several boolean options. 
This approach is not only consistent with what we use for 
unresolveds (UnresolvedPolicy), but also should help to solve a problem 
of options with opposing meanings, mentioned in PR28843

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

llvm-svn: 280209
2016-08-31 08:46:30 +00:00
George Rimar f21aade0d8 [ELF] - Introduce StripPolicy instead of Config->StripAll/StripDebug flags.
This approach is not only consistent with UnresolvedPolicy, 
but also should help to solve a problem 
of options with opposing meanings, mentioned in PR28843

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

llvm-svn: 280206
2016-08-31 08:38:11 +00:00
Eugene Leviant 933dae7435 Implement support for --build-id=uuid switch
Differential revision: https://reviews.llvm.org/D23349

llvm-svn: 279810
2016-08-26 09:55:37 +00:00
George Rimar 86ce267a4a [ELF] - Implemented --oformat binary option.
-oformat output-format
`-oformat' option can be used to specify the binary format for the output object file.

Patch implements binary format output type.

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

llvm-svn: 279726
2016-08-25 09:05:47 +00:00
Petr Hosek 1fb2ecc903 [ELF] Allow specifying the stack size
This option can be used to specify the stack size of the
PT_GNU_STACK segment.

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

llvm-svn: 279013
2016-08-17 23:59:58 +00:00
George Rimar f527a8cd57 [ELF] - Do not exit if -v is specified.
Previously lld showed version number and returned,
that is different from ld and PR28999.

Patch fixed that.

llvm-svn: 278797
2016-08-16 13:25:53 +00:00
Eugene Leviant e4195dc803 [ELF] Add aarch64elf emulation mode
llvm-svn: 278205
2016-08-10 08:19:35 +00:00
Rui Ueyama 84907c5143 Do not pass the SymbolTable to writeResult.
The SymbolTable is always accessible as Symtab<ELFT>::X,
so no need to pass it as an argument.

llvm-svn: 278091
2016-08-09 03:38:23 +00:00
Rui Ueyama 6c50990df6 Add EM_IAMCU support.
This patch adds "-m elf_iamcu" to ldd for IAMCU psABI:
https://github.com/hjl-tools/x86-psABI/wiki/X86-psABI

Patch by H.J Lu.

llvm-svn: 277643
2016-08-03 20:15:56 +00:00
Davide Italiano 38115ffcef [ELF/ARM] Add support for R_ARM_TARGET1 relocation.
Differential Revision:  https://reviews.llvm.org/D22990

llvm-svn: 277369
2016-08-01 19:28:13 +00:00
Peter Collingbourne feee2103c6 COFF: Implement /linkrepro flag.
This flag is implemented similarly to --reproduce in the ELF linker.

This patch implements /linkrepro by moving the cpio writer and associated
utility functions to lldCore, and using that implementation in both linkers.

One COFF-specific detail is that we store the object file from which the
resource files were created in our reproducer, rather than the resource
files themselves. This allows the reproducer to be used on non-Windows
systems for example.

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

llvm-svn: 276719
2016-07-26 02:00:42 +00:00
Rui Ueyama dace838138 Simplify symbol version handling.
r275711 for "speedng up symbol version handling" was committed
by misunderstanding; the benchmark number was measured with
a debug build. The number with a release build didn't actually change.
This patch removes false optimizations added in that patch.

llvm-svn: 276267
2016-07-21 13:13:21 +00:00
Rui Ueyama 77fa5ee160 Remove dead code.
llvm-svn: 275724
2016-07-17 18:27:17 +00:00
Rui Ueyama 69c778c084 Implement almost-zero-cost --trace-symbol.
--trace-symbol is a command line option to watch a symbol.
Previosly, we looked up a hash table for a new symbol if the
option is given. Any code that looks up a hash table for each
symbol is expensive because the linker handles a lot of symbols.
In our design, we look up a hash table strictly only once
for a symbol, so --trace-symbol was an exception.

This patch improves efficiency of the option by merging the
hash table into the symbol table.

Instead of looking up a separate hash table with a string,
this patch sets `Traced` flag to symbols specified by --trace-symbol.
So, if you insert a symbol and get a symbol with `Traced` flag on,
you know that you need to print out a log message for the symbol.
This is nearly zero cost.

llvm-svn: 275716
2016-07-17 17:50:09 +00:00
Rui Ueyama 663b8c2769 Handle versioned symbols efficiently.
Versions can be assigned to symbols in two different ways.
One is the usual version scripts, and the other is special
symbol suffix '@'. If a symbol contains '@', the string after
that is considered to specify a version name.

Previously, we look for '@' for all symbols.

Anything that works on every symbol can be expensive because
the linker has to handle a lot of symbols. The search for '@'
was not an exception.

In this patch, I made two optimizations.

The first optimization is to handle '@' only when at least one
version is defined. If no versions are defined, no versions can
be assigned to any symbols, so it's waste of time to search for '@'.

The second optimization is to scan only suffixes of symbol names
instead of entire symbol names. Symbol names can be very long, but
symbol versions are usually short, so scanning entire symbol names
is waste of time, too.

There are some error cases which we no longer be able to detect
with this patch. I don't think it's a major drawback because they
are minor errors. Speed is more important.

This change improves LLD with debug info self-link time from
6.6993 seconds to 6.3426 seconds (or -5.3%).

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

llvm-svn: 275711
2016-07-17 17:23:17 +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 941faa77ad Remove TargetInfo::getImageBase. NFC.
llvm-svn: 275447
2016-07-14 17:43:28 +00:00
Lang Hames 622ef17f5d [lld] Update LLD for Archive::child_iterator change in LLVM r275361.
llvm-svn: 275362
2016-07-14 02:35:18 +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
Rui Ueyama 1e52f25d46 Add -m elf32_x86_64.
Patch by H.J. Lu.

This patch adds -m elf32_x86_64 to lld. But it doesn't generate working
x32 binaries.

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

llvm-svn: 275236
2016-07-12 23:28:33 +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 c61bcd80af [ELF] - Do not error out when version declaration not found when building executable.
When building executable usually version script is absent.
Before this patch error was shown in the case when
symbol name contained version and there was no script to match it.
  Instead of error out patch allows
to create new version declaration in this case and use it.
gnu linkers do the same.

That is PR28359.

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

llvm-svn: 274828
2016-07-08 06:47:28 +00:00
George Rimar 857644cef8 [ELF] - Implemented --fatal-warnings option.
--fatal-warnings: Treat warnings as errors

DIfferential revision: http://reviews.llvm.org/D21969

llvm-svn: 274504
2016-07-04 13:43:12 +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 93c9af425e Create Strings.cpp and move string manipulation functions to that file.
llvm-svn: 274109
2016-06-29 08:01:32 +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 36b2c0a683 [ELF] - Implemented --no-undefined-version flag
Option checks for cases where a version script explicitly lists
a symbol, but the symbol is not defined and errors out such
cases if any.

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

llvm-svn: 273998
2016-06-28 08:07:26 +00:00
Rui Ueyama b1421a1cec Do not lookup the same option twice. NFC.
llvm-svn: 273771
2016-06-25 04:37:56 +00:00
Davide Italiano e160f0d0d6 [ELF] Allow --reproduce to be specified as an environment variable.
PR: 28257
Differential Revision:   http://reviews.llvm.org/D21628

llvm-svn: 273698
2016-06-24 18:02:50 +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 d60dae8a6a Implement --trace-symbol=symbol option.
Patch by Shridhar Joshi.

This option provides names of all the link time modules which define and
reference symbols requested by user. This helps to speed up application
development by detecting references causing undefined symbols.
It also helps in detecting symbols being resolved to wrong (unintended)
definitions in case of applications containing multiple definitions for
same symbols with different types, bindings.

Implements PR28226.

llvm-svn: 273536
2016-06-23 07:00:17 +00:00
Rafael Espindola f70fb04e4f Make local: optional.
Doing that in an anonymous version is a bit silly, but this opens the
way for supporting it in general.

Since we don't support actual versions, for now we just disable the
version script if we detect that it is missing a local.

llvm-svn: 273000
2016-06-17 13:38:09 +00:00
Rui Ueyama 7b14a62d36 Use StringSwitch. NFC.
llvm-svn: 272030
2016-06-07 17:55:05 +00:00
Peter Smith 8646ced053 Initial support for ARM in lld.
Add support for an ARM Target and the initial set of relocations
    and PLT entries that are necessary for an ARM only hello world to
    link. This has been tested against an ARM only sysroot from the
    4.2.0 CodeSourcery Lite release.
    
    Tests have been added to test/ELF for the support that has been
    implemented.
    
    Main limitations:
    - No Thumb support
    - Relocations incomplete
    - No C++ exceptions support
    - No TLS support
    - No range extension or interworking veneer (thunk) support
    - No Build Attribute support
    - No Big-endian support
    
    The deprecated relocations R_ARM_PLT32 and R_ARM_PC24 have been
    implemented as these are used by the 4.2.0 CodeSourcery Lite release.

llvm-svn: 271993
2016-06-07 09:31:52 +00:00
Rui Ueyama 4ffda7a9cf Create version.txt in a reproduce archive file.
Differential Revision: http://reviews.llvm.org/D21008

llvm-svn: 271901
2016-06-06 15:34:37 +00:00
Rafael Espindola 698dba74f8 Include version in --reproduce.
llvm-svn: 271829
2016-06-05 13:19:39 +00:00
Davide Italiano df24d5b8c8 [LTO] Add --lto-aa-pipeline.
Differential Revision:  http://reviews.llvm.org/D20888

llvm-svn: 271605
2016-06-02 22:58:11 +00:00
Rafael Espindola 3d6d4c39be Handle the -T option.
We were not reading it or including in the --reproduce archive.

llvm-svn: 271367
2016-06-01 06:17:27 +00:00
Rui Ueyama b91bf1a9a0 Do not split mergeable sections if they are gc'ed.
Previously, mergeable section's constructors did more than just
setting member variables; it split section contents into small
pieces. It is not always computationally cheap task because if
the section is a mergeable string section, it needs to scan the
entire section to split them by NUL characters.

If a section would be thrown away by GC, that cost ended up
being a waste of time. It is going to be larger problem if the
section is compressed -- the whole time to uncompress it and
split it up is going to be a waste.

Luckily, we can defer section splitting after GC. We just have
to remember which offsets are in use during GC and apply that later.
This patch implements it.

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

llvm-svn: 270455
2016-05-23 16:55:43 +00:00
Davide Italiano d26c4a14ca [LTO] Add the ability to specify a subset of passes to run.
Differential Revision:  http://reviews.llvm.org/D20267

llvm-svn: 269605
2016-05-15 19:29:38 +00:00
Rui Ueyama fe65877c76 Reorganize the cpio archiver as CpioFile class. NFC.
This code separates the code to create cpio archive from the driver.

llvm-svn: 269593
2016-05-15 17:10:23 +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
George Rimar fa91000290 [ELF] implemented -z defs option
Just do not allow to link shared library if there are
undefined symbols.

This fixes PR27447

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

llvm-svn: 269183
2016-05-11 13:48:41 +00:00
George Rimar c191acf097 [ELF] - Implemented -z combrelocs/nocombreloc.
This is the option which sorts relocs to optimize dynamic linker performance.
-z combelocs is the default in gold, also it ignores -z nocombreloc,
this patch do the same.

Patch sorts relocations by symbols only and do not create any
DT_REL[A]COUNT entries. That is different with what gold/bfd do.

More information about option is here:
http://www.airs.com/blog/archives/186
http://people.redhat.com/jakub/prelink.pdf, p.2

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

llvm-svn: 269066
2016-05-10 15:47:57 +00:00
Rui Ueyama 0cfed297de Handle errors on file opening as soft error.
Also improves the error message. Previously it would just print out
the cause (e.g. "permission denied"). Now it prints out something like
"--reproduce: failed to open foo.cpio: permission denied".

llvm-svn: 268551
2016-05-04 21:05:11 +00:00
Rafael Espindola 2c51e619d5 Print the cpio trailer after every member.
This is both simpler and safer. If we crash at any point, there is a
valid cpio file to reproduce the crash.

Thanks to Rui for the suggestion.

llvm-svn: 268495
2016-05-04 12:47:56 +00:00
Rafael Espindola c5b8ed241d Implement --build-id=none.
Both bfd and gold have this. It allows disabling build-id when it is the
default with by adding -Wl,--build-id=none no the clang command line.

llvm-svn: 268435
2016-05-03 20:55:47 +00:00
Rafael Espindola 1dd2b3d1d0 Produce cpio files for --reproduce.
We want --reproduce to

* not rewrite scripts and thin archives
* work with absolute paths

Given that, it pretty much has to create a full directory tree. On windows that
is problematic because of the very short maximum path limit. On most cases
users can still work around it with "--repro c:\r", but that is annoying and
not viable for automated testing.

We then need to produce some form of archive with the files. The first option
that comes to mind is .a files since we already have code for writing them.
There are a few problems with them

The format has a dedicated string table, so we cannot start writing it until
all members are known.
Regular implementations don't support creating directories. We could make
llvm-ar support that, but that is probably not a good idea.
The next natural option would be tar. The problem is that to support long path
names (which is how this started) it needs a "pax extended header" making this
an annoying format to write.

The next option I looked at seems a natural fit: cpio files.

They are available on pretty much every unix, support directories and long path
names and are really easy to write. The only slightly annoying part is a
terminator, but at least gnu cpio only prints a warning if it is missing, which
is handy for crashes. This patch still makes an effort to always create it.

llvm-svn: 268404
2016-05-03 17:30:44 +00:00
Rafael Espindola 630ccd6a3f Remove unused includes.
llvm-svn: 268381
2016-05-03 13:57:49 +00:00
Rui Ueyama 5002a67ef2 Remove unnecessary namespace specifiers.
llvm-svn: 268292
2016-05-02 19:59:56 +00:00