This is an archive of the discontinued LLVM Phabricator instance.

Fix global variable addressing code generation issue in PIC medium code model
ClosedPublic

Authored by Jianping on Jun 21 2018, 1:03 AM.

Details

Summary

This is to fix the bug on PIC medium code model for global variable addressing.
without this patch,
llc -filetype=asm -code-model=medium -relocation-model=pic x86-64-pic-medium-codemodel.ll –o x86-64-pic-medium-codemodel.s
will report error like
error: 32 bit reloc applied to a field with a different size

movabsq $x@GOTPCREL, %rax
^

X86DAGToDAGISel::matchWrapper, X86::isOffsetSuitableForCodeModel and X86TargetLowering::getGlobalWrapperKind didn't handle the wrapperRIP for medium code model correctly. This patch is fixed this.

Diff Detail

Event Timeline

Jianping created this revision.Jun 21 2018, 1:03 AM
craig.topper added a subscriber: DavidKreitzer.
rnk added a comment.Jun 22 2018, 9:57 AM

I have this change as part of https://reviews.llvm.org/D47211, which I'll try to reland soon.

@rnk, I see that this patch touches isOffsetSuitableForCodeModel , but D47211 does not.

rnk added a comment.Jun 22 2018, 5:09 PM

@rnk, I see that this patch touches isOffsetSuitableForCodeModel , but D47211 does not.

I think this change implements some extra folding that would only be appropriate once we have heuristics in place for classifying "near" and "far" globals. I was thinking we'd implement the logic for classifying globals in clang, since we'll probably want both explicit attributes and size cutoffs, and that we'd mark "near" globals, and unadorned globals would always be treated as far away, requiring GOTPCREL or GOTOFF64 relocations, depending on whether they are known to be dso_local or not.

test/CodeGen/X86/x86-64-codemodel-medium-internal.ll
21–22

This doesn't seem correct. global_arr might be too far away, right?

Jianping accepted this revision.Jun 24 2018, 10:38 PM
In D48417#1140801, @rnk wrote:

I have this change as part of https://reviews.llvm.org/D47211, which I'll try to reland soon.

I re-check again with the latest LLVM codes, this one is the minimal modification to fix the compilation error exposed here.
Once your codes check-in, I think I can abandon this revision.
Thanks

test/CodeGen/X86/x86-64-codemodel-medium-internal.ll
21–22

current LLVM codes will generate the code like this. Because you have enhanced the medium and large code model implementation, this test case need to be removed to reflect more correct result. Thanks

This revision is now accepted and ready to land.Jun 24 2018, 10:38 PM
Jianping closed this revision.Jun 27 2018, 1:16 AM