Verify that the location where a relocation is about the be
applied contains the expected existing value.
This is essentially a sanity check to catch bugs in the compiler
and the linker.
Differential Revision: https://reviews.llvm.org/D44349
llvm-svn: 327325
This bug was found by accident while trying to expand out testcases
for imported symbols, and is covered by the additional test case.
Differential Revision: https://reviews.llvm.org/D44331
llvm-svn: 327290
This matches the existing ordering that's been there for globals
for a while (__stack_pointer coming first).
Differential Revision: https://reviews.llvm.org/D44333
llvm-svn: 327286
This makes the output of some flag names in warning messages consistent with
the output of /? and the output of flags in most other diagnostics.
https://reviews.llvm.org/D44307
llvm-svn: 327261
AFTER keyword is mandatory and consume() was
used by mistake here. We accepted broken script before
this patch, testcase shows the issue.
llvm-svn: 327260
the start of the .got.plt section so that _GLOBAL_OFFSET_TABLE_[0] =
reserved value that is by convention the address of the dynamic section.
Previously we had defined _GLOBAL_OFFSET_TABLE_ as either the start or end
of the .got section with the intention that the .got.plt section would
follow the .got. However this does not always hold with the current
default section ordering so _GLOBAL_OFFSET_TABLE_[0] may not be consistent
with the reserved first entry of the .got.plt.
X86, X86_64, Arm and AArch64 will use the .got.plt. Mips and Power use .got
Fixes PR36555
Differential Revision: https://reviews.llvm.org/D44259
llvm-svn: 327248
toString(T) is a stringize function for an object of type T. Each type
that has that function defined should know how to stringize itself, and
there should be one string representation of an object. Passing a
"supplemental" argument to toString() breaks that princple. We shouldn't
add a second parameter to that function.
Differential Revision: https://reviews.llvm.org/D44323
llvm-svn: 327182
This avoids creating multiple thunks for symbols with aliases or which
belong to ICF'd sections. This patch reduces the size of Chromium for
Android by 260KB (0.8% of .text).
Differential Revision: https://reviews.llvm.org/D44284
llvm-svn: 327154
This error case is described in Linking.md. The operand for call requires
generation of a synthetic stub.
Differential Revision: https://reviews.llvm.org/D44028
llvm-svn: 327151
Previously we created __wasm_call_ctors with null InputFunction, and
added the InputFunction later. Now we create the SyntheticFunction with
null body, and set the body later.
Differential Revision: https://reviews.llvm.org/D44206
llvm-svn: 327149
In what appears to be a copy-and-paste error, lld currently only
installs libraries if the lld tools are configured to build.
Instead, lld should allow the libraries to be installed even if the lld
tools are not being built. Additionally, if users want to only install
the tools and not the libraries, the LLVM way of doing that is by
checking for LLVM_INSTALL_TOOLCHAIN_ONLY.
This fixes PR35960.
llvm-svn: 327126
This fixes the broken tests that were causing failures. The tests
before were verifying that the time stamp was 0, but now that we
are actually writing a timestamp, I just removed the match against
the timestamp value.
llvm-svn: 327049
Our code assumes all input sections in an output SHF_LINK_ORDER
section has SHF_LINK_ORDER flag. We do not check that and that can cause a crash.
That happens because we call
std::stable_sort(Sections.begin(), Sections.end(), compareByFilePosition);,
where compareByFilePosition predicate does not expect to see
null when calls getLinkOrderDep.
The same might happen when sections refer to non-regular sections.
Test cases demonstrate the issues, patch fixes them.
Differential revision: https://reviews.llvm.org/D44193
llvm-svn: 327006
This implements INSERT AFTER in a following way:
During reading scripts it collects all insert statements.
After we done and read all files it inserts statements into script commands list.
With that:
* Rest of code does know nothing about INSERT.
* Approach is straightforward and have no visible limitations.
* It is also easy to support INSERT BEFORE (was seen in clang code once).
* Should work for PR35877 and similar cases.
Cons:
* It assumes we have "main" scripts that describes sections.
Differential revision: https://reviews.llvm.org/D43468
llvm-svn: 327003
We don't need to handle an object file having more than one symbol table,
so as soon as we find the first one, we can process it and then return
from the function.
llvm-svn: 326977
When a symbol is exported via --export=foo but --allow-undefined
is also specified, the symbol is now allowed to be undefined.
Previously we were special casing such symbols.
This combinations of behavior is exactly what emescripten
requires. Although we are trying hard not to allow emscripten
specific features in lld, this one makes sense.
Enforce this behavior by added this case to test/wasm/undefined.ll.
Differential Revision: https://reviews.llvm.org/D44237
llvm-svn: 326976
addElfSymbols and readJustSymbolsFile still has duplicate code, but
I didn't come up with a good idea to eliminate them. Since this patch
is an improvement, I'm sending this for review.
Differential Revision: https://reviews.llvm.org/D44187
llvm-svn: 326972
Windows tools treats the timestamp fields as sort of a build id,
using it to archive executables on a symbol server, as well as
for matching executables to PDBs. We were writing 0 for these
fields, which would cause symbol servers to break as they are
indexed in the symbol server based on this value.
Although the field is called timestamp, it can really be any
value that is unique per build, so to support reproducible builds
we use a hash of the executable here.
Differential Revision: https://reviews.llvm.org/D43978
llvm-svn: 326920
It was raised during the review of D43819.
LLD usually use [X, Y] for reporting ranges, like below:
"relocation R_386_16 out of range: 65536 is not in [0, 65535]"
Patch changes rangeToString() to do the same.
Differential revision: https://reviews.llvm.org/D44207
llvm-svn: 326918
Summary:
I originally tried to simplify code and then noticed that lld doesn't
do what it tells to the user by warn(). It says "unable to order
discarded symbol" but it actually can for sections eliminated by ICF.
With this patch, lld doesn't sort such sections.
Reviewers: jhenderson, rafael
Subscribers: emaste, arichardson, llvm-commits
Differential Revision: https://reviews.llvm.org/D44180
llvm-svn: 326911
LLD uses the debug info and debug line sections to determine the location of
e.g. references to undefined symbols, when producing error messages. In the
event that debug info was present, but debug line parsing failed for some
reason, then a nullptr would end up being dereferenced by the location-lookup
code.
Differential Revision: https://reviews.llvm.org/D44205
Reviewers: grimar
llvm-svn: 326899
With fix: add missing "RUN:" prefix to test case.
Original commit message:
We do not report LMA region overflows currently.
Both GNU linkers do that. The patch implements it.
Differential revision: https://reviews.llvm.org/D44094
llvm-svn: 326895
We do not report LMA region overflows currently.
Both GNU linkers do that. The patch implements it.
Differential revision: https://reviews.llvm.org/D44094
llvm-svn: 326892
Currently, LLD segfaults when linker script attempts to discard
one of the hash sections. This patch fixes that.
Differential revision: https://reviews.llvm.org/D44012
llvm-svn: 326891
It looks like the problem that caused us to originally warn instead of
error was that of a symbol being assigned to the same version twice.
Now we don't warn if a symbol is assigned to the same version twice,
but error if it is assigned to multiple.
This fixes pr28342.
llvm-svn: 326813
We do not expand memory region correctly for following scripts:
.foo.1 :
{
*(.foo.1)
. += 0x1000;
} > ram
Patch generalizes expanding of output sections and memory
regions in one place and fixes the issue.
Differential revision: https://reviews.llvm.org/D43999
llvm-svn: 326688
"division by zero" or "modulo by zero" are not
very informative errors and even probably confusing
as does not let to know that error is coming from linker script.
Patch adds location reporting.
Differential revision: https://reviews.llvm.org/D43934
llvm-svn: 326686
This avoids the Writer unnecessarily having a member to retain ownership
of the function body.
Differential Revision: https://reviews.llvm.org/D43933
llvm-svn: 326580
LLD can not catch a memory area overflow when using a data command.
If we have the script below:
.foo :
{
*(.foo)
BYTE(0x1)
} > ram
where BYTE overflows the ram region, we do not report it currently.
Patch fixes that.
Differential revision: https://reviews.llvm.org/D43948
llvm-svn: 326545
Also remove the space between --lto-O and value, as the option with a
space is not accepted at present.
Leave --opt-remarks-filename as it does not currently accept the = form.
llvm.org/pr36563
llvm-svn: 326536
GNU linkers by convention supports both `--foo bar` and `--foo=bar` styles
for all long options that take arguments.
Differential Revision: https://reviews.llvm.org/D43972
llvm-svn: 326506
Summary:
If an executable needs text relocations, it should be marked as such so
that the loader can prepare for text relocations. We currently create a
dummy segment with DT_TEXTREL for that purpose.
Generic ABI as of 2000 [1] mentioned that "Its [DT_TEXTREL's] use
has been superseded by the DF_TEXTREL flag". However, it's actually not
superseded even after 18 years. OpenBSD and musl recognize only DT_TEXTREL.
So we still need to set both.
[1] http://www.sco.com/developers/gabi/2000-07-17/ch5.dynamic.html
Reviewers: rafael
Subscribers: emaste, llvm-commits, arichardson
Differential Revision: https://reviews.llvm.org/D43920
llvm-svn: 326503
The argument is section=address, not just address.
(For compatibility with GNU linkers we need to, but do not yet, accept
--section-start=section=address.)
llvm-svn: 326463
We intend to maintain compatibility with GNU ld, and in the GNU world
long options are conventionally specified as --long-option=value. For
whatever reason GNU ld.bfd accepts both --long-option value and
--long-option=value, but documents the former. Follow suit.
Some lld long options do not accept the = form; this is probably a bug
to be fixed (along with a man page update).
Reported by Ingo Schwarze, for --entry.
llvm-svn: 326459
For now this is NFC, but this small refactor opens the door to
letting us embed a hash of the PDB in the build id field of the
PDB.
Differential Revision: https://reviews.llvm.org/D43913
llvm-svn: 326453
With the current code if the script has a PHDRS we always obey and try
to allocate a header. This can cause Min - HeaderSize to underflow.
It looks like bfd actually prints an error for this case. With this
patch we do the same.
Found while looking at pr36515.
llvm-svn: 326441
LLD crashes with broken scripts shown in testcase,
because fails to read memory regon name and accesses
MemoryRegions's element which is nullptr.
Patch fixes it.
Differential revision: https://reviews.llvm.org/D43866
llvm-svn: 326431
This is PR36515.
Currenly if we have a script like .debug_info 0 : { *(.debug_info) },
we would not remove this section and keep it in the output.
That does not work, because it is common case for
debug sections to have a zero address expression.
Patch changes behavior so that we remove only sections
that do not use symbols in its expressions.
Differential revision: https://reviews.llvm.org/D43863
llvm-svn: 326430
Previously, we didn't try to make effort to put .note sections next
to each other in the output file, so two .note sections were likely
to be stored to two separate NOTE segments. That's undesirable because
we should create as few segments as possible in general.
Differential Revision: https://reviews.llvm.org/D43858
llvm-svn: 326410
It now includes both linkerscript and non linkerscript variants.
Extracted from a patch by Rui while I was trying to figure out what
exactly was changing.
llvm-svn: 326409
Summary:
This change removes large "echo" commands from the test by writing
tests themselves as linker scripts.
Reviewers: rafael
Subscribers: emaste, javed.absar, llvm-commits, arichardson
Differential Revision: https://reviews.llvm.org/D43900
llvm-svn: 326403
Some linker script test cases contain only a few lines of assembly
and a long linker script. Such tests are easier to maintain if we
write the main test file as a linkier script instead of assembly.
Differential Revision: https://reviews.llvm.org/D43887
llvm-svn: 326363
When merging in types from a type server PDB, we would use a
pointer into the type server PDB's mapped file buffer directly
to avoid copying data. However, we would close the type server
PDB after we finished merging in its types, which would unmap
all of its memory. This would lead to a use after free.
We fix this by making a strong reference in the PDBLinker class
to all referenced type server PDBs, thereby making it safe to
hold pointers into its memory mapped contents.
This fixes llvm.org/pr36455
Differential Revision: https://reviews.llvm.org/D43834
llvm-svn: 326345
This should resolve the issue that lld build fails in some hosts
that uses case-insensitive file system.
Differential Revision: https://reviews.llvm.org/D43788
llvm-svn: 326339