This is an archive of the discontinued LLVM Phabricator instance.

bug33527 - Linker::LinkOnlyNeeded should import AppendingLinkage globals (release_40)
AbandonedPublic

Authored by belleyb on Jun 21 2017, 7:25 AM.

Details

Reviewers
pcc
tejohnson
Summary
  • Linker::LinkOnlyNeeded should always import globals with AppendingLinkage when used in Full-LTO / non-performing-import mode.
  • This the patch against the release_40 branch; 4.0.1-rc2 / revision 304242 to be exact. There's also a review for a fix in trunk. See: https://reviews.llvm.org/D34448

See: https://bugs.llvm.org/show_bug.cgi?id=33527

Diff Detail

Event Timeline

belleyb created this revision.Jun 21 2017, 7:25 AM
belleyb edited the summary of this revision. (Show Details)Jun 21 2017, 7:36 AM
belleyb edited the summary of this revision. (Show Details)Jun 26 2017, 5:07 AM
mehdi_amini added inline comments.Jun 26 2017, 9:09 AM
unittests/Linker/LinkModulesTest.cpp
939

Can this be tested with llvm-lto instead of a gtest? That's the preferred way of testing.

belleyb added inline comments.Jun 26 2017, 9:49 AM
unittests/Linker/LinkModulesTest.cpp
939

No problem. I'll do that.

pcc added inline comments.Jun 26 2017, 9:53 AM
unittests/Linker/LinkModulesTest.cpp
939

You mean llvm-link, right?

belleyb updated this revision to Diff 104142.Jun 27 2017, 5:01 AM

Converted tests to use lit, llvm-link and FileCheck instead of being written as unit tests

belleyb added inline comments.Jun 27 2017, 5:35 AM
lib/Linker/LinkModules.cpp
358

This extra checks at line 357 and 586 are the fix. Without it, the tests below are failing.

The rest of the changes around is only to make the code more readable, allowing me to better document the intent,

test/Linker/only-needed-compiler-used.ll
8 ↗(On Diff #104142)

The linker emits the references to the global variables in a different ordering when the --only-needed is used. This explains the use of the DAG FileCheck option below.

test/Linker/only-needed-ctors2.ll
4 ↗(On Diff #104142)

Note that the test case requires at one of the -internalize or -only-needed flag. Else, a link error is generated about func1 being defined twice. This explains why this particular test case has only 3 runs, instead of 4, like most of the other ones.

test/Linker/only-needed-ctors4.ll
4 ↗(On Diff #104142)

Note that the test case requires at one of the -internalize or -only-needed flag. Else, a link error is generated about func1 being defined twice. This explains why this particular test case has only 3 runs, instead of 4, like most of the other ones.

test/Linker/only-needed-dtors2.ll
4 ↗(On Diff #104142)

Note that the test case requires at one of the -internalize or -only-needed flag. Else, a link error is generated about func1 being defined twice. This explains why this particular test case has only 3 runs, instead of 4, like most of the other ones.

test/Linker/only-needed-dtors4.ll
4 ↗(On Diff #104142)

Note that the test case requires at one of the -internalize or -only-needed flag. Else, a link error is generated about func1 being defined twice. This explains why this particular test case has only 3 runs, instead of 4, like most of the other ones.

test/Linker/only-needed-used.ll
8 ↗(On Diff #104142)

The linker emits the references to the global variables in a different ordering when the --only-needed is used. This explains the use of the DAG FileCheck option below.

10 ↗(On Diff #104142)

This test gives a different result in the release_40 branch than it does in trunk (5.0). I don't know which is correct. I just noticed the difference.

In trunk, the used variables always have global linkage and never internal global linkage, even when the -internalize flag is used. See: https://reviews.llvm.org/D34448

tejohnson edited edge metadata.Jun 27 2017, 8:10 AM

See comments on D34448

I will update this code review once https://reviews.llvm.org/D34448 is approved and submitted.

Abandoning this review. The fix has been submitted to the LLVM trunk (6.0 at this time) as r310522. Moreover, we will soon move to LLVM 5.0...

belleyb abandoned this revision.Aug 10 2017, 5:41 AM