Commit Graph

221 Commits

Author SHA1 Message Date
Rui Ueyama d4b9d068f0 [PECOFF] Fix bug that section grouping may lay out atoms in a wrong order.
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
2013-08-29 07:46:23 +00:00
Rui Ueyama 79e8215f96 [PECOFF] Fix bug that atom size was sometimes wrong.
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
2013-08-29 07:34:58 +00:00
Rui Ueyama 9d52a94cd1 [PECOFF] Make command line options case insensitive to match link.exe's behavior.
llvm-svn: 189505
2013-08-28 20:27:41 +00:00
Rui Ueyama c4d793f2ad Remove an option starting an uppercase character so that the test does not depends on sort order.
llvm-svn: 189423
2013-08-28 00:01:57 +00:00
Rui Ueyama b5292e6295 Modify test to adopt r189416.
r189416 changed the order of command line options shown in help message,
so the test needs adjusting.

llvm-svn: 189417
2013-08-27 23:48:49 +00:00
Rui Ueyama 488d41e6ef [PECOFF] Add the entry symbol and /include symbols to dead strip root set.
Differential Revision: http://llvm-reviews.chandlerc.com/D1527

llvm-svn: 189318
2013-08-27 05:15:20 +00:00
Rui Ueyama bc839fcd3e [PECOFF] Enable dead-stripping by default to match link.exe behavior.
llvm-svn: 189308
2013-08-27 03:38:18 +00:00
Rui Ueyama 4c3184f3c0 Treat entry point symbol as an undefined atom.
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
2013-08-27 03:18:11 +00:00
Shankar Easwaran be81dd757e [lld][ELF] process fini_array sections
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
2013-08-25 18:05:12 +00:00
Rui Ueyama 72165ec8c3 Separates /fixed (no .reloc section) and /dynamicbase (enable ASLR)
in order to match link.exe's behaviour.

Patch by Ron Ofir.

llvm-svn: 189159
2013-08-24 00:39:10 +00:00
Tim Northover 274a023d70 Check for "asserts" rather than "debug" on test
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
2013-08-23 21:10:37 +00:00
Shankar Easwaran f9fe6250ff [lld][ELF] Dont ignore zero sized sections.
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
2013-08-23 20:03:35 +00:00
Shankar Easwaran d9e0a49357 [lld][ELF] Rename typeTLV content type for ELF
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
2013-08-23 20:03:28 +00:00
Shankar Easwaran d17ba4bd4d [lld] handle typeZeroFill atoms in ELF/Native/YAML
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
2013-08-23 20:03:21 +00:00
Shankar Easwaran b8b42658ea [lld][Driver] Fix the unit test for lld gnu flavor
llvm-svn: 188982
2013-08-22 03:18:01 +00:00
Shankar Easwaran c1ea4572ba [lld][Hexagon] Enable Hexagon sdata sorting test
llvm-svn: 188981
2013-08-22 03:02:17 +00:00
Shankar Easwaran e44104b001 add InputGraph functionality
llvm-svn: 188958
2013-08-21 22:57:10 +00:00
Rui Ueyama 8432d32c67 [PECOFF] Treat the common symbol as mergeable symbol.
This is a temporary measure because the semantics of the common symbol is
actually more compilcated than the simple mergeable symbol.

llvm-svn: 188235
2013-08-13 00:03:21 +00:00
Rui Ueyama 43e5fd224a [PECOFF] Fixed base images now have the IMAGE_FILE_RELOCS_STRIPPED flag
Patch by Ron Ofir.

llvm-svn: 188187
2013-08-12 18:11:35 +00:00
Rui Ueyama f1ffe8abbf [PECOFF] Trim at most one character from imported symbols.
The import name is not always the same as the symbol name. If the name/type
field in the import header is NOPREFIX or UNDECORATE, we need to strip some
characters from symbol to get its import name.

The Microsoft PE/COFF spec is vague if symbol contains more than two
consecutive characters to be stripped. We used to strip all characters,
but it doesn't seem right as we couldn't link against the system library
because of this name mangling. Looks like we shouldn't strip more than one
character.

llvm-svn: 188154
2013-08-12 04:10:00 +00:00
Daniel Dunbar bc7bfb1bee [tests] Update to use lit_config and lit package, as appropriate.
llvm-svn: 188093
2013-08-09 18:51:17 +00:00
Rui Ueyama 908606d0a9 [PECOFF] Create __ImageBase symbol.
__ImageBase is a symbol having 4 byte integer equal to the image base address
of the resultant executable. The linker is expected to create the symbol as if
it were read from a file.

In order to emit the symbol contents only when the symbol is actually
referenced, we created a pseudo library file to wrap the linker generated
symbol. The library file member is emitted to the output only when the member
is actually referenced, which is suitable for our purpose.

llvm-svn: 188052
2013-08-09 04:44:15 +00:00
Rui Ueyama dd72278fea [PECOFF] Support COMDAT section that contains mergeable atoms.
The COMDAT section is a section with a special attribute to tell the linker
whether the symbols in the section are allowed to be merged or not. This patch
add a function to interpret the COMDAT data and set "merge" attribute to the
atoms accordingly.

LLD supports multiple policies to merge atoms; atoms can be merged by name or
by content. COFF supports them, and in addition to that, it supports
choose-the-largest-atom policy, which LLD currently does not support. I simply
mapped it to merge-by-name attribute for now, but we eventually have to support
that policy in the core linker.

llvm-svn: 188025
2013-08-08 23:31:50 +00:00
Michael J. Spencer 238cc72ec5 Update to llvm changes.
llvm-svn: 188021
2013-08-08 22:26:50 +00:00
Rui Ueyama a05adfaa90 Update the .drectve section to remove reference to nonexistent files.
llvm-svn: 188011
2013-08-08 21:04:09 +00:00
Rui Ueyama 4ecc59afce [PECOFF] Handle .drectve section.
Summary:
The .drectve section contains linker command line options, and the linker is
expected to interpret them as if they were given via the command line. In this
patch, the command line parser in the driver is called from the object file
reader to parse the string.

I think this patch is important, because this is the first step towards mutable
TargetInfo. We had a discussion about that on llvm-commits mailing list before.
I haven't removed "const" from the function signature yet. Instead, I just use
cast to remove "const". This is a temporary aid for an experiment. If we don't
see any issue with this mutable TargetInfo appraoch, I'll change the function
signature, and rename the class LinkerContext from TargetInfo.

Reviewers: kledzik

CC: llvm-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D1246

llvm-svn: 187677
2013-08-02 21:26:14 +00:00
Rui Ueyama 8a14aa1bd9 [PECOFF] Relocations now take into account the address which is stored at the relocation site
Patch by Ron Ofir.

llvm-svn: 187664
2013-08-02 18:40:50 +00:00
Rui Ueyama 8344be8407 [PECOFF] A symbol with symbol with section number 0 and non-zero value represents a BSS atom.
llvm-svn: 187645
2013-08-02 05:25:31 +00:00
Rui Ueyama dcf09476ff [PECOFF] Emit BSS section.
llvm-svn: 187460
2013-07-30 22:56:46 +00:00
Rui Ueyama b469aeb164 [PECOFF] Process Import Name/Type field in the import library.
This patch removes hacky mangle() function, which strips all decorations
uncondtitionally. LLD now interprets Import Name/Type field in the import
library properly as described in the Microsoft PE/COFF Spec.

llvm-svn: 187388
2013-07-29 22:55:39 +00:00
Rui Ueyama 5b274f3414 Fix test failure introduced in r187271 by enabling pipefail.
llvm-svn: 187381
2013-07-29 21:50:33 +00:00
Rui Ueyama c3ab5117c9 [PECOFF] Skip a section if there's no atom in the section.
Some sections, such as with IMAGE_SCN_LNK_REMOVE attribute, is skipped
in the first pass. Such sections need to be skipped in the latter passes.

llvm-svn: 187281
2013-07-27 00:37:50 +00:00
Rui Ueyama d5b49de621 [PECOFF] Don't set IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE if "-fixed" is provided
Based on Ron Ofir's patch.

llvm-svn: 187221
2013-07-26 17:30:39 +00:00
Reid Kleckner f33c0e3a5f Use env in a pecoff test so it passes with the lit shell test runner
llvm-svn: 187170
2013-07-25 23:20:21 +00:00
Reid Kleckner 818104899e Add yaml2obj to check-lld deps, since the PECOFF tests need it
llvm-svn: 187165
2013-07-25 23:05:13 +00:00
Rui Ueyama de25a69531 [PECOFF][Driver] Allow multiple /include options.
llvm-svn: 187100
2013-07-25 02:57:39 +00:00
Rui Ueyama d1d116aa89 [PECOFF] Use Windows style options instead of Unix style as primary options.
LLD still accepts both Unix and Windows style options when it's run as
link.exe. This patch does not change functionality.

llvm-svn: 187086
2013-07-24 23:18:02 +00:00
Rui Ueyama fd50283c3c [PECOFF] Add /include command line option.
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
2013-07-24 22:53:23 +00:00
Nick Kledzik 2815782831 Add lit magic so that lld unittests are run as part of lld test suite
llvm-svn: 187005
2013-07-23 23:42:17 +00:00
Rui Ueyama 6a41fca856 [PECOFF] Support -fixed command line option to disable base relocations.
llvm-svn: 186911
2013-07-23 01:29:50 +00:00
Rui Ueyama 8e6c8f850d [PECOFF][Driver] Add -base command line option.
llvm-svn: 186739
2013-07-20 00:45:00 +00:00
Rui Ueyama 99f80cf4a7 [PECOFF][Driver] Process "LINK" environment variable.
llvm-svn: 186654
2013-07-19 05:06:20 +00:00
Rui Ueyama 64b29d616b [PECOFF][Driver] Add -defaultlib command line option.
llvm-svn: 186650
2013-07-19 04:11:37 +00:00
Rui Ueyama 5a7bbce587 [PECOFF][Driver] Interpret "LIB" environment variable.
llvm-svn: 186648
2013-07-19 03:27:03 +00:00
Rui Ueyama 2897feb7e0 [PECOFF] Use library search path when looking for a .lib file.
llvm-svn: 186645
2013-07-19 02:18:25 +00:00
Nick Kledzik 4f44eff707 build lld unittests as part of lld-test target
llvm-svn: 186441
2013-07-16 18:46:48 +00:00
Rui Ueyama 341a2b4b5d [PECOFF][Writer] Emit .reloc section.
Emit .reloc section. This is the first step to support DLL creation. The
executable doesn't need .reloc section, but the DLL does.

Reviewers: Bigcheese

CC: llvm-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D1126

llvm-svn: 186336
2013-07-15 18:43:01 +00:00
Rui Ueyama c8a53795ab [PECOFF] Support linking against DLL.
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
2013-07-11 08:46:21 +00:00
Rui Ueyama a3635b7b3b [PECOFF][Writer] Fixed a bug that an empty section is emit to the section header.
llvm-svn: 186066
2013-07-11 05:43:38 +00:00
Rui Ueyama d769cec6e3 [PECOFF] Use yaml2obj to avoid checking in binary files.
llvm-svn: 185690
2013-07-05 10:41:44 +00:00