Commit Graph

196 Commits

Author SHA1 Message Date
Peter Collingbourne e02775f068 ELF: Add ThinLTO caching support.
This patch adds an option named --thinlto-cache-dir, which specifies the
path to a directory in which to cache native object files for ThinLTO
incremental builds.

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

llvm-svn: 296702
2017-03-01 23:00:10 +00:00
George Rimar 87b0d68633 [ELF] - Implemented --no-dynamic-linker option
Feature is used for producing static-linked PIE executables
(https://gcc.gnu.org/ml/gcc/2015-06/msg00008.html)
And was implemented in GNU ld https://gcc.gnu.org/ml/gcc/2015-08/msg00099.html

I also found it in linux kernel build system,
though I think that x86/x64 bootloader does not really rely on it.
Seems it used for PPC though.

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

llvm-svn: 296097
2017-02-24 08:26:18 +00:00
Davide Italiano db4b0a7194 [LTO] Add support for optimization remarks.
Differential Revision:  https://reviews.llvm.org/D29878

llvm-svn: 294971
2017-02-13 17:49:18 +00:00
George Rimar 82bd8be6d8 Recommit r294464 "[ELF] - Added partial support for --emit-relocs (no --gc-section case, no /DISCARD/ support) #3"
with temporarily file name fix in testcase.

Original commit message:

-q, --emit-relocs - Generate relocations in output

Simplest implementation: 
* no GC case, 
* no "/DISCARD/" linkerscript command support.

This patch is extracted from D28612 / D29636,

Relative to PR31579.

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

llvm-svn: 294469
2017-02-08 16:18:10 +00:00
George Rimar 0b2cc8190d Reverted r294464 "[ELF] - Added partial support for --emit-relocs (no --gc-section case, no /DISCARD/ support) #3"
Broked build bot:
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/5835/steps/test/logs/stdio

llvm-svn: 294466
2017-02-08 16:10:14 +00:00
George Rimar d6ae624552 [ELF] - Added partial support for --emit-relocs (no --gc-section case, no /DISCARD/ support) #3
-q, --emit-relocs - Generate relocations in output

Simplest implementation: 
* no GC case, 
* no "/DISCARD/" linkerscript command support.

This patch is extracted from D28612 / D29636,

Relative to PR31579.

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

llvm-svn: 294464
2017-02-08 15:53:33 +00:00
Rui Ueyama 98469e4de5 Accept `-trace-symbol foo` as well as `-trace-symbol=foo`.
llvm-svn: 293854
2017-02-02 02:21:47 +00:00
Davide Italiano f8ff8fca22 [ELF] Add warn-unresolved-symbols/error-unresolved-symbols options
Patch by Dmitry Mikulin.
PR: 31735

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

llvm-svn: 293139
2017-01-26 02:19:20 +00:00
Rui Ueyama b2a23cf3c0 Do not allocate space for common symbols with -r
Currently ld.lld -r allocates space for common symbols, whereas ld.bfd
-r doesn't.  As a result the OpenBSD makefile bits for creating libraries
fail as they use ld -X -r to strip local symbols, which results in
duplicate symbol errors because space for the common symbols has been
allocated.

The diff also implements the --define-commons option such that allocation
of commons can be forced even if -r is used.

Patch by Mark Kettenis.

llvm-svn: 292878
2017-01-24 03:41:20 +00:00
Rui Ueyama 71e3e3a5c1 Move a flag definition to the right place as -demangle is not ignored.
llvm-svn: 292049
2017-01-15 03:45:46 +00:00
Rui Ueyama ea3f6c3a7e Add -no-{export-dynamic,fatal-warnings}.
llvm-svn: 292048
2017-01-15 03:38:55 +00:00
Rui Ueyama 1705f99c77 Add -print-map and -M options.
llvm-svn: 292046
2017-01-15 02:52:34 +00:00
Rui Ueyama 9c6cdc2022 Add a help text for -Map.
llvm-svn: 292045
2017-01-15 02:52:14 +00:00
Rafael Espindola 1ebfc59c89 Implement -Map.
The format is not exactly the same as the one in bfd since bfd always
follows a linker script and prints it along.

llvm-svn: 291958
2017-01-13 21:05:46 +00:00
Rui Ueyama 8781c425b3 Make -color-diagnostics an alias to -color-diagnostics=always.
Previously, that was an alias to -color-diagnostics=auto. However,
Clang's -fcolor-diagnostics is an alias to -fcolor-diagnostics=always,
so that was confusing. This patch fixes that issue.

llvm-svn: 290332
2016-12-22 08:20:28 +00:00
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
George Rimar b86448c669 [ELF] - Accept --sort-section=xxx command form.
--sort-section=xxx is the same as --sort-section xxx,
was found in one of FreeBSD ports.

llvm-svn: 289938
2016-12-16 11:59:52 +00:00
George Rimar 6cbfce7785 [ELF] - Make LLD accept Ttext-segment X/Ttext-segment=X aliases for -Ttext.
It os used in work/emulators/qemu-user-static port.
Which tries to use -Ttext-segment and then:

# In case ld does not support -Ttext-segment, edit the default linker
# script via sed to set the .text start addr.  This is needed on FreeBSD
# at least.
<here it calls -verbose to extract and edit default bfd linker script.>

Actually now we are do not fully support -Ttext properly (see D27613),
but we also seems never will provide anything close to default script, like bfd do,
so at least this patch introduces proper alias handling.

llvm-svn: 289827
2016-12-15 16:12:34 +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 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 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 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 838ff4d5c5 Accept -script=<file> in addition to -script <file>.
Fixes PR31126.

llvm-svn: 287711
2016-11-22 22:54:03 +00:00
Rui Ueyama 8a44c94b8a Remove '.' from a help message.
llvm-svn: 287692
2016-11-22 20:15:35 +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 23f441d3ac Add -no-threads option that negates the effect of -threads.
llvm-svn: 287072
2016-11-16 01:39:50 +00:00
George Rimar e784395c99 [ELF] - Ignore -Map,-M and --cref options.
-M, --print-map Write map file on standard output
-Map MAPFILENAME Write map file
--cref	Output cross reference table

This is relative to PR30973.

Next FreeBSD ports were atm failing because of 
lack of -Map, -M and --cref:

sysutils/openipmi
emulators/adamem
devel/jwasm
net/pimd
devel/k8048
textproc/libcrm114
lang/micropython
net/mrouted
print/openprinting

After this patch all of them can be link fine.

llvm-svn: 286831
2016-11-14 14:45:11 +00:00
George Rimar e93e0adbb5 Reverted r286451 "[ELF] - Allow separate form for -f (alias for -auxiliary)."
Though the patch was technically correct,
the only FreeBSD port (noticed atm) that tried using it was
www/mod_jk. And it seems just passed gcc option to linker by mistake:

"-Wl,-L-L/usr/local/lib -Wl,-rpath,/usr/local/lib -Wl,-fstack-protector -Wl,-fstack-protector -o mod_jk.la "

Given that it is an easy mistake to make, reverting for now.

llvm-svn: 286458
2016-11-10 14:48:39 +00:00
George Rimar f5a0ef97f5 [ELF] - Allow separate form for -f (alias for -auxiliary).
Without that FreeBSD port was failing with next confuxing error:
/usr/bin/ld: error: unknown argument: -fstack-protector

llvm-svn: 286451
2016-11-10 14:07:15 +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
George Rimar 470de71177 [ELF] - Add separate form for -R alias.
During link of devel/chrpath (FreeBSD port), found next issue:
/usr/bin/ld: error: unclosed comment in a linker script
/usr/bin/ld: error: line 1: unknown directive: �
/usr/bin/ld: error: ��

Problem was not obvious and the reason was that we did not accept
the separate form of -R. While invocation line contained it:
cc -Wl,-R /usr/local/lib -o prog prog.c

CPIO file produced contained /usr/local/lib file. 
Which looks because of reasons above
contained inside the content of whole lib folder, 
and it then was passed as an input and
proccessed as linker script.

llvm-svn: 286378
2016-11-09 16:38:15 +00:00
George Rimar 25143dfd48 [ELF] - Ignore -stats command line option.
llvm-svn: 286348
2016-11-09 08:59:59 +00:00
George Rimar a705ab175d [ELF] - Accept both "-" and "--" for Ttext/Tdata/Tbss options.
llvm-svn: 285900
2016-11-03 12:49:25 +00:00
George Rimar 6a0855470f [ELF] - Allow "-Ttext xxx", "-Tbss xxx", "-Tdata bss" commandline.
So patch just defines an alias for -Txxx=YYY forms,
this is consistent with ld and should fix PR30814.

llvm-svn: 285824
2016-11-02 16:06:00 +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
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
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
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
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
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
Rui Ueyama a60058c8f5 Fix -output option.
Usually, options that are longer than one character can be preceded
either by "-" or "--", but options starting with "o" are exceptions
because they conflict with "-o" option. They have to be preceded by
"--".

llvm-svn: 281004
2016-09-09 00:25:56 +00:00
Rui Ueyama 881406e787 Define '-undefined foo' as an alias to '-undefined=foo'.
llvm-svn: 280985
2016-09-08 20:35:29 +00:00
Ed Maste 4d9947ba09 ELF: Add -Qy as ignored option
GCC passes it by default on powerpc64 on FreeBSD. GNU ld claims "this
option is ignored for SVR4 compatibility", so we can ignore it too.

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

llvm-svn: 280864
2016-09-07 21:10:25 +00:00
George Rimar bcbbb3987d [ELF] - Sort command line options. NFC.
llvm-svn: 280803
2016-09-07 11:43:18 +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 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 449cf3e44a Removed trailing whitespace. NFC.
llvm-svn: 279729
2016-08-25 10:39:04 +00:00