This restores the debug output to how it was before r197727 broke it. This
went undetected because the corresponding test was never run due to broken
feature detection.
llvm-svn: 202079
Syntactically /SAFESEH is a boolean flag -- you can pass /SAFESEH or /SAFESEH:no.
The meaning of /SAFESEH is as follows.
- If /SAFESEH is specified, the linker will produce an executable with SEH table.
If any input files are not compatible with SEH, it's an error.
- If /SAFESEH:no is specified, the linker will not emit SEH table even if all
input files are compatible with SEH.
- If no option is specified, the linker emits SEH table if all input files are
compatible with SEH.
llvm-svn: 201895
Add new virtual virtual function `isRelaOutputFormat` to the
`ELFLinkingContext` class. Call this function everywhere we need to
select a relocation table format.
Patch reviewed by Shankar Easwaran and Rui Ueyama.
llvm-svn: 199973
Refactor the parser so that the parser can return arbitrary type of parse
result other than a vector of ExportDesc. Parsers for non-EXPORTS directives
will be implemented in different patches. No functionality change.
llvm-svn: 198993
The main goal of this patch is to allow "mach-o encoded as yaml" and "native
encoded as yaml" documents to be intermixed. They are distinguished via
yaml tags at the start of the document. This will enable all mach-o test cases
to be written using yaml instead of checking in object files.
The Registry was extend to allow yaml tag handlers to be registered. The
mach-o Reader adds a yaml tag handler for the tag "!mach-o".
Additionally, this patch fixes some buffer ownership issues. When parsing
mach-o binaries, the mach-o atoms can have pointers back into the memory
mapped .o file. But with yaml encoded mach-o, name and content are ephemeral,
so a copyRefs parameter was added to cause the mach-o atoms to make their
own copy.
llvm-svn: 198986
Module-definition (.def) files are the file containing linker directives,
such as export symbols. Because link.exe supports the same features as command
line options, just as some Linker Script commands overlaps with command line
options, use of module-definition file is not really necessary. It provides
an alternative way to specify some linker options.
This patch implements EXPORTS directive. Other directives will be implemented
in the future.
llvm-svn: 198925
Each export symbol descriptor has unique name attribute, so std::set is
better container than std::vector for it. No functionality change.
llvm-svn: 198102
It will configure resonable defaults for other settings in the
MachOLinkingContext object based on the parameters.
Patch by Joe Ranieri
llvm-svn: 197851
Default ordinals were assigned in EdataPass, and the assigned values were
then discarded in the pass. No code other than EdataPass would not be able
to get all of the information about ordinals. That's not ideal since I'm
writing code to emit an Import Library file, which also needs ordinals.
This is a patch to move the code to assign default ordinals from EdataPass
to LinkingContext::verify(), so that assigned ordinals will be available
anywhere.
No functionality change.
llvm-svn: 197797
The main changes are in:
include/lld/Core/Reference.h
include/lld/ReaderWriter/Reader.h
Everything else is details to support the main change.
1) Registration based Readers
Previously, lld had a tangled interdependency with all the Readers. It would
have been impossible to make a streamlined linker (say for a JIT) which
just supported one file format and one architecture (no yaml, no archives, etc).
The old model also required a LinkingContext to read an object file, which
would have made .o inspection tools awkward.
The new model is that there is a global Registry object. You programmatically
register the Readers you want with the registry object. Whenever you need to
read/parse a file, you ask the registry to do it, and the registry tries each
registered reader.
For ease of use with the existing lld code base, there is one Registry
object inside the LinkingContext object.
2) Changing kind value to be a tuple
Beside Readers, the registry also keeps track of the mapping for Reference
Kind values to and from strings. Along with that, this patch also fixes
an ambiguity with the previous Reference::Kind values. The problem was that
we wanted to reuse existing relocation type values as Reference::Kind values.
But then how can the YAML write know how to convert a value to a string? The
fix is to change the 32-bit Reference::Kind into a tuple with an 8-bit namespace
(e.g. ELF, COFFF, etc), an 8-bit architecture (e.g. x86_64, PowerPC, etc), and
a 16-bit value. This tuple system allows conversion to and from strings with
no ambiguities.
llvm-svn: 197727
/DLLEXPORT is a command line option to export a symbol. __declspec(dllexport)
uses that to make the linker to export DLLExport'ed functions, by adding the
option to .drectve section.
This patch implements the parser of the command line option.
llvm-svn: 197122
This patch is to basically move the functionality to construct Data Directory
from IdataPass to WriterPECOFF.
Data Directory is a part of the PE/COFF header and contains the addresses of
the import tables.
We used to represent the link from Data Directory to the import tables as
relocation references. The idea behind it is that, because relocation
references are processed by the Writer, we wouldn't have to do anything special
to fill the addresses of the import tables. I thought that the addresses would
be set "automatically".
But it turned out that that design made the pass and the writer rather
complicated. In order to make relocation references between Data Directory to
the import tables, these data structures needed to be represented as Atom.
However, because Data Directory is not a section content but a part of the
PE/COFF header, it did not fit well as an Atom. So we ended up having
complicated code both in IdataPass and the writer.
This patch simplifies it.
One side effect of this patch is that we now have ".idata.a", ".idata.d" and
"idata.t" sections for the import address table, the import directory table,
and the import lookup table. The writer looks for the sections by name to find
the start addresses of the sections. We probably should have a better way to
find a specific atom from the core linking result, but currently using the
section name seems to be the easiest way to do that. The Windows loader do not
care about the import table's section layout.
llvm-svn: 197016
/ALTERNATENAME is a rarely-used, undocumented command line option that is
needed to link LLD for release build. It seems that the option is for defining
an weak alias; /alternatename:foo=bar defines weak symbol "foo" for "bar".
If "foo" is defined in an input file, it'll be linked normally and the command
line option will have no effect. If it's not defined, "foo" will be handled
as an alias for "bar".
This patch implements the parser for the option. The actual weak alias handling
will be implemented in a separate patch.
llvm-svn: 196743
Because compare() and its heper functions no longer have to be members of
LayoutPass class, we can remove it from the class. No functionality change.
llvm-svn: 196715
The comparator used in the layout pass has many calls of map::find(). Because
std::sort runs the comparator N*log2(N) times, the maps are looked up with the
same key again and again. The map lookup is not a very fast operation. It made
the pass slow.
This patch eliminates the duplicate map lookups using decorate-sort-undecorate
idiom. The pass used to take 1.1 seconds when linking LLD with LLD on Windows,
but it now takes only 0.3 seconds. Overall performance gain in that case is from
6.1 seconds to 5.2 seconds.
Differential Revision: http://llvm-reviews.chandlerc.com/D2358
llvm-svn: 196714
Currently we do not de-duplicate library files specified by /defaultlib option.
As a result, the same files are added multiple times to the input graph. In
particular, some popular files, such as kernel32.lib or oldnames.lib, are added
more than 10 times during linking of LLD. That makes the linker slower, as it
needs to parse the same file again and again.
This patch solves the issue by de-duplicating. The same file will be added only
once to the input graph. This patch improved the LLD linking time from 10.5
seconds to 7.7 seconds on my 4-core Core i7 Macbook Pro.
llvm-svn: 196504
/MERGE option is a bit complicated for many reasons. Firstly, it takes both
positive and negative arguments. That means we have to have one of three
distinctive values (set, clear or unchange) for each permission bit. In this
patch we represent the three values using two bitmasks.
Secondly, the permissions specified by the parameter is bitwise or-ed with the
default permissions of a section. There is an exception for that rule; if one
of READ, WRITE or EXECUTE bit is specified, unspecified bits need to be
cleared. (So if you specify only WRITE for example, the resulting section will
not have WRITE nor EXECUTE bits.)
Lastly, multiple /merge options are allowed.
llvm-svn: 195882
Looks like -L paths are not positional. They need to be added to a list of
search paths and those needs to be searched when lld looks for a library.
llvm-svn: 195594
This adds LinkerScript support by creating a type Script which is of type
FileNode in the InputGraph. Once the LinkerScript Parser converts the
LinkerScript into a sequence of command, the commands are handled by the
equivalent LinkerScript node for the current Flavor/Target. For ELF, a
ELFGNULdScript gets created which converts the commands to ELF nodes and ELF
control nodes(ELFGroup for handling Group nodes).
Since the Inputfile type has to be determined in the Driver, the Driver needs
to determine the complete path of the file that needs to be processed by the
Linker. Due to this, few tests have been removed since the Driver uses paths
that doesnot exist.
llvm-svn: 195583
Hidden nodes could be a result of expansion, where a flavor might decide to keep
the node that we want to expand but discard it from being processed by the
resolver.
Verifies with unittests.
llvm-svn: 195516
Flavors may like to expand InputGraph nodes, when a filenode after parsing
results in more elements. One such example is while parsing GNU linker scripts.
The linker scripts after parsing would result in a lot of filenodes and probably
controlnodes too.
Adds unittests to verify functionality.
llvm-svn: 195515
This adds functionality to limit shared library undefined atoms to be added
only once by the Resolver.
Dynamic libraries may be processed more than once if they exist within a
Group.
Also adds a test to verify the change.
llvm-svn: 195307
This patch adds support for converting normalized mach-o to and from binary
mach-o. It also changes WriterMachO (which previously directly wrote a
mach-o binary given a set of Atoms) to instead do it in two steps. The first
step uses normalizedFromAtoms() to convert Atoms to normalized mach-o, and the
second step uses writeBinary() which to generate the mach-o binary file.
llvm-svn: 194167
These fields are for /align option. Section alignment can be set per-section
basis with /section option too. In order to avoid name conflicts, rename the
existing identifiers to become more specific. No functionality change.
llvm-svn: 194160
/section command line option is to set/reset attributes of the Characteristics
field in the section header. You can set non-default values with this option.
You can make .data section executable with this, for example.
This patch implements the parser of the command line option. The code to use
the parsed values will be committed in a separate patch.
llvm-svn: 194133
/defaultlib options can be specified implicitly via the .drectve section, and
it's pretty common that multiple object files add the same library, such as
user32.lib, to the input. We shouldn't add the same library multiple times.
llvm-svn: 194129
Enable this for the following flavors
a) core
b) gnu
c) darwin
Its disabled for the flavor PECOFF. Convenient markers are added with FIXME
comments in the Driver that would be removed and code removed from each flavor.
llvm-svn: 193585
More important than any performance concerns, the code was dropping the
temporary string on the floor after assigning it to a StringRef, and
then used the StringRef later. Caught by running the LLD tests under
ASan.
llvm-svn: 193486
/merge:<from>=<to> option makes the linker to combine "from" section to "to"
section. This patch is to parse the option. The actual feature will be
implemented in a subsequent patch.
llvm-svn: 193454
Disable tests to be run with REQUIRES: disable. Note disable is not added to the
config by the test runner Mkaefiles, so essentially disables the test.
Code changes would be required to fix these tests :-
test/darwin/hello-world.objtxt
test/elf/check.test
test/elf/phdr.test
test/elf/ppc.test
test/elf/undef-from-main-dso.test
test/elf/X86_64/note-sections-ro_plus_rw.test
test/pecoff/alignment.test
test/pecoff/base-reloc.test
test/pecoff/bss-section.test
test/pecoff/drectve.test
test/pecoff/dynamic.test
test/pecoff/dynamicbase.test
test/pecoff/entry.test
test/pecoff/hello.test
test/pecoff/imagebase.test
test/pecoff/importlib.test
test/pecoff/lib.test
test/pecoff/multi.test
test/pecoff/reloc.test
test/pecoff/weak-external.test
llvm-svn: 193300
Instead of making the linker to create a manifest XML file in the same
directory as the resulting binary, you can embed the XML as a part of
resource into the executable.
In order to do that, the linker first creates a resource script file containing
the XML file, compile it into a binary resource file with RC.EXE, and then
convert it to a COFF file with CVTRES.EXE.
llvm-svn: 193298
/manifestfile:<path> specifies an alternative manifest file output path.
Default is "<output-path>.manifest" where <output-path> is the executable's
path.
llvm-svn: 193195
The manifest file is an XML file that conveys some information to the loader,
such as whether the executable needs to run as Administrator or not. This patch
is to parse command line option for manifest file.
Actual XML file generation will be done in a separate patch.
llvm-svn: 193141
This patch fixes a bug in r190608. The results of a comparison function
passed to std::sort must be transitive, which is, if a < b and b < c, and if
a != b, a < c must be also true. CompareAtoms::compare did not actually
guarantee the transitivity. As a result the sort results were sometimes just
wrong.
Consider there are three atoms, X, Y, and Z, whose file ordinals are 1, 2, 3,
respectively. Z has a property "layout-after X". In this case, all the
following conditionals become true:
X < Y because X's ordinal is less than Y's
Y < Z because Y's ordinal is less than Z's
Z < X because of the layout-after relationship
This is not of course transitive. The reason why this happened is because
we used follow-on relationships for comparison if two atoms falls in the same
follow-on chain, but we used each atom's properties if they did not. This patch
fixes the issue by using follow-on root atoms for comparison to get consistent
results.
Differential Revision: http://llvm-reviews.chandlerc.com/D1980
llvm-svn: 193029
Instead of showing multiple lines of debug messages, show only one message
by CompareAtoms::operator(). Here is an example.
Before:
Sorting _main .text
Sorting by sectionPos(2,2)
Sorting by override
Sorting _main .text
Sorting by sectionPos(2,2)
Sorting by override
After:
Layout: '_main' > '.text' (override (1, 0))
Layout: '_main' > '.text' (override (1, 0))
Differential Revision: http://llvm-reviews.chandlerc.com/D1964
llvm-svn: 192941
Dead-strip root symbols can be undefined atoms, but should not really be
nonexistent, because dead-strip root symbols should be added to initial
undefined atoms at startup. Whenever you look up its name in the symbol
table, some type of atom will always exist.
llvm-svn: 192831
A file with .objtxt extension is parsed in readFile(), but because we did not
propagate that information to the calling side, calling side would try to parse
it again. This patch will fix the issue by adding an extra parameter to
readFile().
llvm-svn: 192311
This change removes code in various places which was setting the File Ordinals.
This is because the file ordinals are assigned by the way files are resolved.
There was no other way than making the getNextFileAndOrdinal be set const and
change the _nextOrdinal to mutable.
There are so many places in code, that you would need to cleanup to make
LinkingContext non-const!
llvm-svn: 192280
This associates resolveState to FileNodes. The control node derive
their resolution state from the inputElements that are contained in
it.
This makes --start-group/--end-group to work with ELF linking.
llvm-svn: 192269
Summary:
The original code with enum "_" is intended to emulate scoped enums.
Now we have real scoped enums, so use it.
Reviewers: Bigcheese
CC: llvm-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D1852
llvm-svn: 192148
This is the first step in how I plan to get mach-o object files support into
lld. We need to be able to test the mach-o Reader and Write on systems without
a mach-o tools. Therefore, we want to support a textual way (YAML) to represent
mach-o files.
MachONormalizedFile.h defines an in-memory abstraction of the content of mach-o
files. The in-memory data structures are always native endianess and always
use 64-bit sizes. That internal data structure can then be converted to or
from three different formats: 1) yaml (text) encoded mach-o, 2) binary mach-o
files, 3) lld Atoms.
This patch defines the internal model and uses YAML I/O to implement the
conversion to and from the model to yaml. The next patch will implement
the conversion from normalized to binary mach-o.
This patch includes unit tests to validate the yaml conversion APIs.
llvm-svn: 192147
Changes :-
a) Functionality in InputGraph to insert Input elements at any position
b) Functionality in the Resolver to use nextFile
c) Move the functionality of assigning file ordinals to InputGraph
d) Changes all inputs to MemoryBuffers
e) Remove LinkerInput, InputFiles, ReaderArchive
llvm-svn: 192081
This adds an option --output-filetype that can be set to either
YAML/Native(case insensitive). The linker would create the outputs
associated with the type specified by the user.
Changes all the tests to use the new option.
llvm-svn: 191183
If a subclass does not override the member function, the superclass's method
takes care of string conversion of "file not found" error. This is a reasonable
default behavior. Subclasses are still able to override to customize error
messages.
llvm-svn: 191058
This also makes it support debugging executables built with lld.
Initial patch done by Bigcheese. This is only a revised patch to
have the functionality in the Writer.
llvm-svn: 191032
So that we can determine what the target architecture is. Adding this
field does not mean that we are going to support non-i386 architectures
soon; there are many things to do to support them, and I'm focusing on
i386 now. But this is the first step toward multi architecture support.
llvm-svn: 190627
In COFF, an undefined symbol can have up to one alternative name. If a symbol
is resolved by its regular name, then it's linked normally. If a symbol is not
found in any input files, all references to the regular name are resolved using
the alternative name. If the alternative name is not found, it's a link error.
This mechanism is called "weak externals".
To support this mechanism, I added a new member function fallback() to undefined
atom. If an undefined atom has the second name, fallback() returns a new undefined
atom that should be used instead of the original one to resolve undefines. If it
does not have the second name, the function returns nullptr.
Differential Revision: http://llvm-reviews.chandlerc.com/D1550
llvm-svn: 190625
Mangling scheme varies on platform, and prepending an underscore is valid only
on 32-bit x86. Added a method to mangle name to PECOFFLinkingContext and use
it to avoid hard coding mangled names.
llvm-svn: 190585
attribute in LinkerInput to isWholeArchive and use that for deciding
whether library archives should be expanded. Implement the -all_load
option of the Darwin linker using this flag and drop the support for it
in GNU mode.
llvm-svn: 190275
It looks like there is a possibility of seeing RO/RW note sections
and we would need to create an appropriate RO/RW segment associated
with them.
Adds a test too.
llvm-svn: 189907
The compiler is allowed to add a linker option starting with -?<name> to
.drectve section. If the linker can interpret -<name>, it's processed as if
there's no question mark there. If not, such option is silently ignored.
This is a COFF's feature to allow the compiler to emit new linker options
while keeping compatibility with older linkers.
llvm-svn: 189897
This changes the interface of createLinkerInput to use ErrorOr, so that
errors from the linker can be captured.
Also adds a convenience function for error strings to be returned from
file nodes.
llvm-svn: 189871
This creates .init_array/.fini_array section for X86_64 ELF
targets and executes init/fini functions specified by the
-init/-fini options respectively.
llvm-svn: 189719
This adds an API to the LinkingContext for flavors to add Internal files
containing atoms that need to appear in the YAML output as well, when -emit-yaml
switch is used.
Flavors can add more internal files for other options that are needed.
llvm-svn: 189718
With this patch the entry symbol is treated as an undefined symbol, to force
the resolver to resolve the entry symbol.
Differential Revision: http://llvm-reviews.chandlerc.com/D1524
llvm-svn: 189307
typeTLV content type is used by Darwin to represent thread local
storage. A new contentType has to be made to represent ELF
thread local storage data. These have been set to
- typeThreadZeroFill (represents TBSS storage)
- typeThreadData (represents TDATA storage)
llvm-svn: 189137
BSS atoms dont take any file space in the Input file. They are associated
with a contentType(typeZeroFill). Similiar zero fill types also exist which
have the same meaning in terms of occupying file space in the Input.
These atoms have to be handled seperately when writing to the
lld's intermediate file or the lld test infrastructure.
Also adds a test.
llvm-svn: 189136
Also change some local variable names: "ti" -> "context" and
"_targetInfo" -> "_context".
Differential Revision: http://llvm-reviews.chandlerc.com/D1301
llvm-svn: 187823
Missing files will be reported as errors in the later pass, so this patch
does not change the behavior of the LLD linker, but it helps writing unit
tests for the driver.
llvm-svn: 187256
The /include command line option is equivalent to Unix --undefined
option, which forces the linker to resolve the given symbol name
as if it's an unresolved symbol in one of its input files. This feature
is used to link an additional object file or a shared library that no
input files refer to.
llvm-svn: 187084
This patch adds a new pass, IdataPass, to transform shared atom references
to real references and to construct the .idata section data. With this patch
lld can produce a working Hello World program by linking it against
kernel32.dll and user32.dll.
Reviewers: Bigcheese
CC: llvm-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D1096
llvm-svn: 186071
This renames variable name to reflect initial undefined symbols that are
defined by the linker -u option.
This doesnot change any functionality in lld, and updates code to reflect
Nick's comment.
llvm-svn: 184682
This change moves the functionality of undefinedSymbols that were created in
ELFTargetInfo into TargetInfo. Looks like MachO/Windows use similiar options
like in ELF for creating undefined symbols when the linker is invoked.
Address comment from Ruiu.
(No change in functionality, except moving the functionality from ELF to
TargetInfo, so that multiple architectures can use the same)
llvm-svn: 184398
Architecture specific code should reside in architecture specific directory
not in Atom. Looks like there are no efforts being made at this moment to
support ARM, so let's remove it for now.
Reviewers: Bigcheese
CC: llvm-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D959
llvm-svn: 183877
The yaml reader is not specific to any file format. This patch moves
it to TargetInfo and makes validate a non virtual interface so that it
can be constructed from a single location.
The same method will be used to create a reader for llvm bitcode
files.
llvm-svn: 183740
Found that having a method to check the strucutre of the followon graph makes
it easy to debug file readers. The method checks if there's no wrong edge in
followOnNexts and followOnRoots. It is called only when debuggging is enabled
for LayoutPass.
Reviewers: shankarke
CC: llvm-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D922
llvm-svn: 183553
lld can now output a valid Windows executable with a text section that does nothing
but just returns immediately. It's not able to handle relocations, symbol tables,
data sections, etc, so it still can't do anything practical, though.
Reviewers: Bigcheese
CC: llvm-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D892
llvm-svn: 183478
This is the parser for the ENTRY command. Note that because the parsing result
is currentlyd discarded, lld can parse but just ignore the command.
Reviewers: Bigcheese
CC: llvm-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D833
llvm-svn: 183141
Users can override the default value of the dynamic linker to be set to the
one that appears in the command line. The path can even be empty!.
Added a test for the option.
llvm-svn: 182889
Add WinLinkDriver and connect it to the existing COFF reader. Remaining
parts are still stubs, so while it can now read a COFF file, it still
cannot link or output PE/COFF files yet.
Reviewers: Bigcheese
CC: llvm-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D865
llvm-svn: 182784
Summary: "W" bit value was not consistent in ContentPermissions enum. It should always be 2.
Reviewers: kledzik
CC: llvm-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D810
llvm-svn: 182515
only if they are relative. This removes the FIXME when the
relocations are being emitted and checks if the relocation
is relative and only then populates the addend information.
I couldnt add a testcase for this as llvm-readobj lacks
functionality of printing dynamic relocations.
When the functionality is added, remove the commented lines
from elf/ifunc.test to test functionality.
llvm-svn: 182077
Summary:
Split buildFollowOnTable to small functions to improve
code readability and remove code duplication. No change
in functionality.
CC: llvm-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D790
llvm-svn: 181749
We need to acquire a lock before signal a condition.
Otherwise threads waiting on a condition variable can
miss a signal.
Consider two threads: Thread A executing dec() and thread
B executing sync(). The initial value of _count is 1. If
these two threads are interleaved in the following order,
thread B misses the signal sent by thread A, because at the
time thread A sends a signal, B is not waiting for it.
Thread A | Thread B
| std::unique_lock<std::mutex> lock(_condMut);
| while (!(_count == 0)) {
if (--_count == 0) |
_cond_notify_all() |
| _cond.wait();
| }
Note that "wait(lock, pred)" is equivalent to "while(!pred())
wait(lock)", so I expanded it in the above example.
Reviewers: Bigcheese
CC: llvm-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D764
llvm-svn: 181484
Summary:
Add the explicit keyword to one-parameter
constructors to prevent unintended type conversions.
CC: llvm-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D765
llvm-svn: 181483