Skip to content

Commit 6cea7c4

Browse files
authored
[X86] Always use 64-bit relocations in no-PIC large code model (llvm#89101)
This matches other types of relocations, e.g. to constant pool. And makes things more consistent with PIC large code model. Some users of the large code model may not place small data in the lower 2GB of the address space (e.g. ClangBuiltLinux/linux#2016), so just unconditionally use 64-bit relocations in the large code model. So now functions in a section not marked large will use 64-bit relocations to reference everything when using the large code model. This also fixes some lldb tests broken by llvm#88172 (https://lab.llvm.org/buildbot/#/builders/68/builds/72458).
1 parent b1dc62f commit 6cea7c4

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

llvm/lib/Target/X86/X86ISelDAGToDAG.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -2927,11 +2927,10 @@ bool X86DAGToDAGISel::selectAddr(SDNode *Parent, SDValue N, SDValue &Base,
29272927
}
29282928

29292929
bool X86DAGToDAGISel::selectMOV64Imm32(SDValue N, SDValue &Imm) {
2930-
// Cannot use 32 bit constants to reference objects in kernel code model.
2931-
// Cannot use 32 bit constants to reference objects in large PIC mode since
2932-
// GOTOFF is 64 bits.
2930+
// Cannot use 32 bit constants to reference objects in kernel/large code
2931+
// model.
29332932
if (TM.getCodeModel() == CodeModel::Kernel ||
2934-
(TM.getCodeModel() == CodeModel::Large && TM.isPositionIndependent()))
2933+
TM.getCodeModel() == CodeModel::Large)
29352934
return false;
29362935

29372936
// In static codegen with small code model, we can get the address of a label

llvm/test/CodeGen/X86/code-model-elf.ll

+2-2
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ define dso_local ptr @lea_forced_small_data() #0 {
350350
;
351351
; LARGE-STATIC-LABEL: lea_forced_small_data:
352352
; LARGE-STATIC: # %bb.0:
353-
; LARGE-STATIC-NEXT: movl $forced_small_data, %eax
353+
; LARGE-STATIC-NEXT: movabsq $forced_small_data, %rax
354354
; LARGE-STATIC-NEXT: retq
355355
;
356356
; SMALL-PIC-LABEL: lea_forced_small_data:
@@ -403,7 +403,7 @@ define dso_local i32 @load_forced_small_data() #0 {
403403
;
404404
; LARGE-STATIC-LABEL: load_forced_small_data:
405405
; LARGE-STATIC: # %bb.0:
406-
; LARGE-STATIC-NEXT: movl $forced_small_data+8, %eax
406+
; LARGE-STATIC-NEXT: movabsq $forced_small_data+8, %rax
407407
; LARGE-STATIC-NEXT: movl (%rax), %eax
408408
; LARGE-STATIC-NEXT: retq
409409
;

0 commit comments

Comments
 (0)