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
We should dead-strip atoms only if they are created for COMDAT symbols. If we
remove non-COMDAT atoms from a binary, it will no longer be guaranteed that
the binary will work correctly.
In COFF, you can manipulate the order of section contents in the resulting
binary by section name. For example, if you have four sections
.data$unique_prefix_{a,b,c,d}, it's guaranteed that the contents of A, B, C,
and D will be consecutive in the resulting .data section in that order.
Thus, you can access B's and C's contents by incrementing a pointer pointing
to A until it reached to D. That's why we cannot dead-strip B or C even if
no one is directly referencing to them.
Some object files in the standard library actually use that technique.
llvm-svn: 193017
INT 3 (machine code 0xCC) will raise an interrupt when executed. That is better
for filling the gap than NOP because we want to stop the execution immediately
when the control reached to non-code address.
llvm-svn: 192945
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
There are aliases for --start-group/--end-group options represented
by -( and -) respectively in the command line.
This change adds and improves the test for the alias options to be
tested.
Looks like users use this option widely than explicitly using
--start-group/--end-group.
llvm-svn: 192470
allowRemainingUndefines() is already checked in Resolver::resolve(), so we
don't need to check it again after returning from it. It's actually not only
superfluous but buggy because a failure of resolve() does not always mean that
there is a remaining undefines.
llvm-svn: 192423
-- so that command line options to specify new input files, such as
/defaultlib:foo, is handled properly. Such options were ignored before
this patch.
llvm-svn: 192342
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
Output to llvm::err() is not guaranteed to be thread-safe, so it needs
to be guarded with a lock.
Differential Revision: http://llvm-reviews.chandlerc.com/D1862
llvm-svn: 192250
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
Found this with asan. Code assumes that find doesn't return end, thus if
both atoms didn't have followon roots it would still compare their positions.
llvm-svn: 191865
This will eventually need to be refactored to better handle COPY relocations,
as other relocations can also generate them. I'm not yet sure the exact
circumstances in which they are needed yet.
llvm-svn: 191567
This patch inverts the return value of these functions, so that they return
"true" on success and "false" on failure. The meaning of boolean return value
was mixed in LLD; for example, InputGraph::validate() returns true on success.
With this patch they'll become consistent.
CC: llvm-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D1748
llvm-svn: 191341
/PDBALTPATH:<path> is an option to embed a different path for the PDB file to
the binary than the actual PDB file location. Because we don't support PDB
file, we'll just ignore the option for now.
llvm-svn: 191273
We used to support both Windows and Unix style command line options. In Windows
style, an option and its value are separated by ":" (colon). In Unix, separator
is a space. Accepting both styles were convenient, but we can no longer allow
Unix style because I found that can be ambiguous.
For example, /nodefaultlib option takes an optional argument. In Windows style
it's going to be something like "/nodefaultlib:foo". There's no ambiguity what
"foo" means. However, if the option is "/nodefaultlib foo", "foo" can be
interpreted either an optional argument for "/nodefaultlib" or an input file
"foo.obj". We should just stop accepting the non-standard command line style.
llvm-svn: 191247
These options are to enable DLL delay loading. If enabled, DLL is loaded
at run time by a helper routine when a function in the DLL is actually called
for the first time, instead of making the Windows loader to load all DLLs at
startup time. This should shorten startup delay if an executable have many
imported symbols.
The linker needs to create a "delayed import table" and link delayimp.lib in
which helper functions are defined to support the feature.
For now, we just ignore the options, so that the linker does not complain when
it sees these options. We want to support them in the future.
llvm-svn: 191232
Summary:
This patch changes WriterPECOFF to actually write down the address instead of ignoring it.
Also, it changes the order of adding the BaseReloc chunk as otherwise the address wasn't set yet.
I think a better way of doing it would be to change DataDirectoryAtom to create a Reference
instead of using a number, and to change IdataPass accordingly, but I'm not sure how to do that.
Reviewers: ruiu
Reviewed By: ruiu
CC: llvm-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D1743
llvm-svn: 191220
Summary: This patch changes WritePECOFF to calculate the value of the SizeOfHeaders PE header field instead of just using 512.
Reviewers: rui314, ruiu
Reviewed By: ruiu
CC: llvm-commits, ruiu
Differential Revision: http://llvm-reviews.chandlerc.com/D1708
llvm-svn: 191212
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
GNU LD driver only understood no_such_file_or_directory error and was showing
just "Unknown Error" for any other type of error. With this patch, the driver
now prints file name and error message string by default.
llvm-svn: 191070
/incremental is an option to enable incremental linking. We will eventually
want to implement the feature for better performance, but in the meantime,
we want to just ignore the option so that the linker does not output unknown
option error when it sees /incremental option.
llvm-svn: 191063
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
/errorReport is a command line option to let the linker to report internal
linker error information to Microsoft. For LLD that option doesn't make any
sense, so it just ignores the option.
llvm-svn: 191044
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
Base relocation block should be aligned on a 32-bit boundary. While the PECOFF
spec mentions only aligning the blocks, and not padding them, link.exe seems
to add an extra IMAGE_REL_I386_ABSOLUTE entry (just a zeroed WORD) in order to
pad the blocks.
Patch by Ron Ofir.
llvm-svn: 190951
This sets the sectionChoice property for DefinedAtoms. The output section name
is derived by the property of the atom. This also decreases native file size.
Adds a test.
llvm-svn: 190840
This patch changes lld to go through all sections while calculating the size
for SizeOfCode, SizeOfInitializedData and SizeOfUninitializedData fields in the
PE header, instead of using only a small set of hard-coded sections.
This only really changes SizeOfInitializedData which didn't include .reloc
section before this patch.
Patch by Ron Ofir.
llvm-svn: 190799
This patch sets the IMAGE_SCN_MEM_DISCARDABLE characteristic to the base
relocations section in order to match MS PECOFF specification.
Patch by Ron Ofir.
llvm-svn: 190798
There was a bug that if a section has an alignment requirement and there are
multiple symbols at offset 0 in the section, only the last atom at offset 0
would be aligned properly. That bug would move only the last symbol to an
alignment boundary, leaving other symbols unaligned, although they should be at
the same location. That caused a mysterious SEGV error of the resultant
executable.
With this patch, we manage all symbols at the same location properly, rather
than keeping the last one.
llvm-svn: 190724
Alignment(1) does not mean that the atom should be aligned on a 1 byte
boundary but on a 2^1 boundary. So, atoms without any specific alignment
requirements should have Alignment(0).
llvm-svn: 190723
This handles multiple weak symbols which appear back to back. This fix is needed
which otherwise will lead to symbols getting initialized to arbitrary values.
There was a constructor/destructor test that really triggered this to be fixed
on X86_64.
Adds a test.
llvm-svn: 190658
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
We need to order atoms that exist in the same chain. This is to make sure that
the command line order is preserved when we emit the atoms to the output file.
Credits: BigCheese for finding the bug.
Adds a test which otherwise would fail.
llvm-svn: 190608
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
Process::GetEnv() uses GetEnvironmentVariableW, which is a Windows API
to get an environment variable and is preferable over getenv().
llvm-svn: 190431
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
Before this patch, name of driver implementation is not consistent with its
option table file. Specifically, LDOptions has a different prefix than
GnuLdDriver.
This patch renames option files, so that the option files have the same prefix
as the corresponding driver files.
Differential Revision: http://llvm-reviews.chandlerc.com/D1591
llvm-svn: 189895
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
We added layout edges to the head atoms in grouped sections. That was wrong,
because the head atom needs to be followed by the other atoms in the *same*
section, not by the other section contents. With this patch, layout edges are
added from tail atom, which is the last atom in a section, to head atom.
llvm-svn: 189573
Because of a bug, the last atom of each section contained a garbage at the
end of its data. In most cases the garbage is harmless but it could have cause
SEGV.
llvm-svn: 189572
We were creating undefined atoms for common symbols by mistake. That did not
lead to a link failure, for undefined atoms would be resolved by common symbols
in the same file, but that's a waste of resource.
llvm-svn: 189534
We scanned the symbol table twice; first to gather all regular symbols, and
second to process aux symbols. That's a bit inefficient and complicated. We
can instead cache aux symbols in the first pass, to eliminate the need of the
second pass.
llvm-svn: 189525
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
The cleanup includes :-
* Rename ambiguous Header class to ELFHeader
* Convert Chunk contentype and kind to be a enumerated class
* Remove functions that are not being used, avoids future confusion
llvm-svn: 189209
This change processes fini_array section in addition to processing
init_array sections. This also makes functions registered at compile
time for initialization and finalization to be run during execution
llvm-svn: 189196
This completes the subsystem name parsing to support the identifiers that the
Microsoft link.exe linker supports. "windows" and "console" are left as the
first items as they are the expected common paths.
Signed-off-by: Saleem Abdulrasool <compnerd@compnerd.org>
llvm-svn: 189181
The debug flag being checked for seems to be controlled by whether the
build is asserts/non-asserts rather than debug/non-debug. Mostly these
correlate, but not necessarily.
As far as I can tell with various combinations of debug/assetions this
change makes no difference on autotools builds, but fixes a check-all
failure with CMake.
llvm-svn: 189147
There may be relocations that may be pointing to the section
even if the section sizes are 0. We shouldnot ignore them
for that regard.
llvm-svn: 189139
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
Previously, the CMake build would look for llvm-tblgen to determine
if a directory is an LLVM build or install directory. Since we don't
want to include llvm-tblgen in the install, look for llvm-config instead,
and use that to find llvm-tblgen.
(This is the lld equivalent of Clang r189127.)
llvm-svn: 189128
This used to be handled automagically by the option parsing library,
but after LLVM r188314, we should handle it ourselves.
No functionality change, but adds a test.
llvm-svn: 188318