Commit Graph

38 Commits

Author SHA1 Message Date
Michael Kuperstein
7cc2dbbdb1 gold-plugin: fix test to allow default visibility on local symbols
GNU ld sets default, not hidden, visibility on local symbols. 
Having default or hidden visibility on local symbols makes no difference in run-time behavior.

Patch by: H.J. Lu <hjl.tools@gmail.com>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229297 91177308-0d34-0410-b5e6-96231b3b80d8
2015-02-15 09:32:30 +00:00
Chandler Carruth
15db81893f [gold] Consolidate the gold plugin options and actually search for
a gold binary explicitly. Substitute this binary into the tests rather
than just directly executing the 'ld' binary.

This should allow folks to inject a cross compiling gold binary, or in
my case to use a gold binary built and installed somewhere other than
/usr/bin/ld. It should also allow the tests to find 'ld.gold' so that
things work even if gold isn't the default on the system.

I've only stubbed out support in the makefile to preserve the existing
behavior with none of the fancy logic. If someone else wants to add
logic here, they're welcome to do so.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229251 91177308-0d34-0410-b5e6-96231b3b80d8
2015-02-14 09:43:57 +00:00
Jan Wen Voung
0dfec56734 Gold-plugin: Broaden scope of get/release_input_file to scope of Module.
Summary:
Move calls to get_input_file and release_input_file out of
getModuleForFile(). Otherwise release_input_file may end up
unmapping a view of the file while the view is still being
used by the Module (on 32-bit hosts).

Fix for PR22482.

Test Plan: Add test using --no-map-whole-files.

Reviewers: rafael, nlewycky

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D7539

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228842 91177308-0d34-0410-b5e6-96231b3b80d8
2015-02-11 16:12:50 +00:00
Rafael Espindola
0a2caa143f Fix linking of shared libraries.
In shared libraries the plugin can see non-weak declarations that are still
undefined.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226031 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-14 20:08:46 +00:00
Rafael Espindola
55c86a8cdc Fix handling of extern_weak. This was broken by r225983.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226026 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-14 19:43:32 +00:00
Rafael Espindola
5f92811f30 Handle a symbol being undefined.
This can happen if:
* It is present in a comdat in one file.
* It is not present in the comdat of the file that is kept.
* Is is not used.

This should fix the LTO boostrap.

Thanks to Takumi NAKAMURA for setting up the bot!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225983 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-14 13:53:50 +00:00
Rafael Espindola
f907a26bc2 Change the .ll syntax for comdats and add a syntactic sugar.
In order to make comdats always explicit in the IR, we decided to make
the syntax a bit more compact for the case of a GlobalObject in a
comdat with the same name.

Just dropping the $name causes problems for

@foo = globabl i32 0, comdat
$bar = comdat ...

and

declare void @foo() comdat
$bar = comdat ...

So the syntax is changed to

@g1 = globabl i32 0, comdat($c1)
@g2 = globabl i32 0, comdat

and

declare void @foo() comdat($c1)
declare void @foo() comdat

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225302 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-06 22:55:16 +00:00
Rafael Espindola
f214fe8b32 Remember the unmangled name in the plugin.
This allows it to work with non trivial manglings like the one in COFF.

Amusingly, this can be tested with gold, as emit-llvm causes the plugin to
exit before any COFF is generated.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223790 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-09 16:50:57 +00:00
Rafael Espindola
823f3d2e34 This test requires asserts because of -stats.
Sorry about that.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222788 91177308-0d34-0410-b5e6-96231b3b80d8
2014-11-25 20:56:56 +00:00
Rafael Espindola
2fbbd7a369 gold plugin: call llvm_shutdown so that -stats works.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222787 91177308-0d34-0410-b5e6-96231b3b80d8
2014-11-25 20:52:49 +00:00
Rafael Espindola
f1ca1d4bc3 Add a disable-output option to the gold plugin.
This corresponds to the opt option and is handy for profiling.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222687 91177308-0d34-0410-b5e6-96231b3b80d8
2014-11-24 21:18:14 +00:00
Rafael Espindola
e4e7ad3101 Fix the test.
It was broken since r221708.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221783 91177308-0d34-0410-b5e6-96231b3b80d8
2014-11-12 14:23:04 +00:00
Rafael Espindola
d07e7ecd85 Enable the slp vectorizer in the gold plugin.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220887 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-30 00:38:54 +00:00
Rafael Espindola
74ded7c790 Enable the loop vectorizer in the gold plugin.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220886 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-30 00:11:24 +00:00
Rafael Espindola
25016f9d2e Replace also-emit-llvm with save-temps.
The also-emit-llvm option only supported getting the IR before optimizations.
This patch replaces it with a more generic save-temps option that saves the IR
both before and after optimizations.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220885 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-29 23:54:45 +00:00
Rafael Espindola
61c4e41480 gold plugin: Handle gold selecting a linkonce GV when a weak is present.
The plugin API doesn't have the notion of linkonce, only weak. It is up to the
plugin to figure out if a symbol used only for the symbol table can be dropped.
In particular, it has to avoid dropping a linkonce_odr selected by gold if there
is also a weak_odr.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219188 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-07 04:06:13 +00:00
Rafael Espindola
4f17a54bfa gold plugin: create internal replacement with original linkage first.
The call to copyAttributesFrom will copy the visibility, which might assert
if it were to produce something invalid like "internal hidden". We avoid it
by first creating the replacement with the original linkage and then setting
it to internal affter the call to copyAttributesFrom.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219184 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-07 03:19:55 +00:00
Rafael Espindola
3ddd4fa0dd gold plugin: Remap function arguments when creating a replacement function.
When creating an internal function replacement for use in an alias we were
not remapping the argument uses in the instructions to point to the new
arguments.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219177 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-07 00:47:38 +00:00
Peter Collingbourne
394be6c159 LTO: introduce object file-based on-disk module format.
This format is simply a regular object file with the bitcode stored in a
section named ".llvmbc", plus any number of other (non-allocated) sections.

One immediate use case for this is to accommodate compilation processes
which expect the object file to contain metadata in non-allocated sections,
such as the ".go_export" section used by some Go compilers [1], although I
imagine that in the future we could consider compiling parts of the module
(such as large non-inlinable functions) directly into the object file to
improve LTO efficiency.

[1] http://golang.org/doc/install/gccgo#Imports

Differential Revision: http://reviews.llvm.org/D4371

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218078 91177308-0d34-0410-b5e6-96231b3b80d8
2014-09-18 21:28:49 +00:00
Rafael Espindola
2bfef929c0 Internalize common symbols when we can.
This fixes pr20974.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217981 91177308-0d34-0410-b5e6-96231b3b80d8
2014-09-17 20:41:13 +00:00
Rafael Espindola
3c278b1c12 Remember to eraseFromParent after replaceAllUsesWith.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217536 91177308-0d34-0410-b5e6-96231b3b80d8
2014-09-10 19:39:41 +00:00
Rafael Espindola
19f3868e91 Handle common linkage correctly in the gold plugin.
This is the plugin version of pr20882.

This handles the case of every common symbol being in the IR. We will need some
support from gold to handle the case where some symbols are in ELF and some in
the IR.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217458 91177308-0d34-0410-b5e6-96231b3b80d8
2014-09-09 20:08:22 +00:00
Rafael Espindola
1455ac7a30 The gold tests also require ppc to be compiled in.
We could create a tools/gold/PowerPC and a tools/gold/X86, but it doesn't seem
worth it.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217267 91177308-0d34-0410-b5e6-96231b3b80d8
2014-09-05 19:01:12 +00:00
Rafael Espindola
c359193486 Update to not depend on "llvm-objdump -d -symbolize".
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217047 91177308-0d34-0410-b5e6-96231b3b80d8
2014-09-03 16:16:02 +00:00
Rafael Espindola
03d2823e02 Add support for comdats to the gold plugin.
There are two parts to this. First, the plugin needs to tell gold the comdat by
setting comdat_key.

What gets things a bit more complicated is that gold only seems
symbols. In particular, if A is an alias to B, it only sees the symbols
A and B. It can then ask us to keep symbol A but drop symbol B. What
we have to do instead is to create an internal version of B and make A
an alias to that.

At some point some of this logic should be moved to lib/Linker so that
we don't map a Constant to an internal version just to have lib/Linker
map that again to the destination module.

The reason for implementing this in tools/gold for now is simplicity.
With it in place it should be possible to update clang to use comdats
for constructors and destructors on ELF without breaking the LTO
bootstrap. Once that is done I intend to come back and improve the
interface lib/Linker exposes.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216302 91177308-0d34-0410-b5e6-96231b3b80d8
2014-08-22 23:26:10 +00:00
Rafael Espindola
3fd7e37b34 Rewrite the gold plugin to fix pr19901.
There is a fundamental difference between how the gold API and lib/LTO view
the LTO process.

The gold API talks about a particular symbol in a particular file. The lib/LTO
API talks about a symbol in the merged module.

The merged module is then defined in terms of the IR semantics. In particular,
a linkonce_odr GV is only copied if it is used, since it is valid to drop
unused linkonce_odr GVs.

In the testcase in pr19901 both properties collide. What happens is that gold
asks us to keep a particular linkonce_odr symbol, but the IR linker doesn't
copy it to the merged module and we never have a chance to ask lib/LTO to keep
it.

This patch fixes it by having a more direct implementation of the gold API. If
it asks us to keep a symbol, we change the linkage so it is not linkonce. If it
says we can drop a symbol, we do so. All of this before we even send the module
to lib/Linker.

Since now we don't have to produce LTO_SYMBOL_SCOPE_DEFAULT_CAN_BE_HIDDEN,
during symbol resolution we can use a temporary LLVMContext and do lazy
module loading. This allows us to keep the minimum possible amount of
allocated memory around. This should also allow as much parallelism as
we want, since there is no shared context.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216215 91177308-0d34-0410-b5e6-96231b3b80d8
2014-08-21 20:28:55 +00:00
Rafael Espindola
8b14a499f9 Make the test a bit more strict.
Before it would pass even if @b or @c ended up pointing to a variable named
@a123.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215450 91177308-0d34-0410-b5e6-96231b3b80d8
2014-08-12 15:55:27 +00:00
Rafael Espindola
f531e92671 Add a plugin testcase for merging weak variables.
I initially thought I could implement COMDATs with aliases by just
internalizing GVs instead of dropping them. This is a counter
example: Internalizing one of the @a would make @b and @c point
to different variables.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215447 91177308-0d34-0410-b5e6-96231b3b80d8
2014-08-12 15:39:14 +00:00
Rafael Espindola
b2d2f28351 Fix using -plugin-opt=apiflie when also using -plugin-opt=emit-llvm.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215378 91177308-0d34-0410-b5e6-96231b3b80d8
2014-08-11 19:06:54 +00:00
Rafael Espindola
1f4ef379d2 Fix test failure on ARM.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215140 91177308-0d34-0410-b5e6-96231b3b80d8
2014-08-07 20:33:06 +00:00
Rafael Espindola
936a1b573b Add a test showing the interaction of linker scripts and plugin.
In particular, the linker script is processed early enough for function g
to be internalized.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@214916 91177308-0d34-0410-b5e6-96231b3b80d8
2014-08-05 19:56:53 +00:00
Rafael Espindola
d59fa04f04 Add a small test showing when a linkonce_odr symbol can be hidden.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@214311 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-30 15:31:21 +00:00
Rafael Espindola
df7568e9f3 gold plugin: Fix handling of corrupted bitcode files.
We should still claim them and tell gold about the error.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@214214 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-29 20:46:19 +00:00
Rafael Espindola
800b4d1157 Add a test for the mtriple plugin option.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@214186 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-29 17:27:07 +00:00
Rafael Espindola
3bc40273a8 Test the linker plugin handling of llvm.used.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@214116 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-28 20:42:29 +00:00
Rafael Espindola
3ee48e0c0a Add tests for the various emit-llvm plugin options.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@214102 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-28 17:37:25 +00:00
Rafael Espindola
ceda947999 Test the mcpu option.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@214087 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-28 14:44:33 +00:00
Rafael Espindola
12cc465b43 Start adding some tests for the gold plugin.
These are only used when the 'ld' in the path is gold and the plugin has
been built, but it is already a start to make sure we don't regress features
that cannot be tested with llvm-lto.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@214058 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-27 23:11:06 +00:00