Skip to content

[X86] Always use 64-bit relocations in no-PIC large code model #89101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2024

Conversation

aeubanks
Copy link
Contributor

@aeubanks aeubanks commented Apr 17, 2024

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 #88172 (https://lab.llvm.org/buildbot/#/builders/68/builds/72458).

This matches other types of relocations, e.g. to constant pool.

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.
@aeubanks aeubanks requested a review from rnk April 17, 2024 17:11
@llvmbot
Copy link
Member

llvmbot commented Apr 17, 2024

@llvm/pr-subscribers-backend-x86

Author: Arthur Eubanks (aeubanks)

Changes

This matches other types of relocations, e.g. to constant pool.

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.


Full diff: https://github.com/llvm/llvm-project/pull/89101.diff

2 Files Affected:

  • (modified) llvm/lib/Target/X86/X86ISelDAGToDAG.cpp (+3-4)
  • (modified) llvm/test/CodeGen/X86/code-model-elf.ll (+2-2)
diff --git a/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp b/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
index 4e4241efd63d6b..7dcde2a508949d 100644
--- a/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
+++ b/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
@@ -2927,11 +2927,10 @@ bool X86DAGToDAGISel::selectAddr(SDNode *Parent, SDValue N, SDValue &Base,
 }
 
 bool X86DAGToDAGISel::selectMOV64Imm32(SDValue N, SDValue &Imm) {
-  // Cannot use 32 bit constants to reference objects in kernel code model.
-  // Cannot use 32 bit constants to reference objects in large PIC mode since
-  // GOTOFF is 64 bits.
+  // Cannot use 32 bit constants to reference objects in kernel/large code
+  // model.
   if (TM.getCodeModel() == CodeModel::Kernel ||
-      (TM.getCodeModel() == CodeModel::Large && TM.isPositionIndependent()))
+      TM.getCodeModel() == CodeModel::Large)
     return false;
 
   // In static codegen with small code model, we can get the address of a label
diff --git a/llvm/test/CodeGen/X86/code-model-elf.ll b/llvm/test/CodeGen/X86/code-model-elf.ll
index 0da62e3e7a6519..f60f75bc26911e 100644
--- a/llvm/test/CodeGen/X86/code-model-elf.ll
+++ b/llvm/test/CodeGen/X86/code-model-elf.ll
@@ -350,7 +350,7 @@ define dso_local ptr @lea_forced_small_data() #0 {
 ;
 ; LARGE-STATIC-LABEL: lea_forced_small_data:
 ; LARGE-STATIC:       # %bb.0:
-; LARGE-STATIC-NEXT:    movl $forced_small_data, %eax
+; LARGE-STATIC-NEXT:    movabsq $forced_small_data, %rax
 ; LARGE-STATIC-NEXT:    retq
 ;
 ; SMALL-PIC-LABEL: lea_forced_small_data:
@@ -403,7 +403,7 @@ define dso_local i32 @load_forced_small_data() #0 {
 ;
 ; LARGE-STATIC-LABEL: load_forced_small_data:
 ; LARGE-STATIC:       # %bb.0:
-; LARGE-STATIC-NEXT:    movl $forced_small_data+8, %eax
+; LARGE-STATIC-NEXT:    movabsq $forced_small_data+8, %rax
 ; LARGE-STATIC-NEXT:    movl (%rax), %eax
 ; LARGE-STATIC-NEXT:    retq
 ;

@MaskRay
Copy link
Member

MaskRay commented Apr 17, 2024

64 bit abs relocation without large section flag? Worth clarifying

@aeubanks
Copy link
Contributor Author

updated description

@aeubanks aeubanks merged commit 6cea7c4 into llvm:main Apr 17, 2024
5 of 6 checks passed
@aeubanks aeubanks deleted the large-64 branch April 17, 2024 19:04
llvmbot pushed a commit to llvmbot/llvm-project that referenced this pull request Apr 17, 2024
…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).

(cherry picked from commit 6cea7c4)
tstellar pushed a commit to llvmbot/llvm-project that referenced this pull request Apr 23, 2024
…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).

(cherry picked from commit 6cea7c4)
@pointhex pointhex mentioned this pull request May 7, 2024
Zentrik added a commit to Zentrik/llvm-project that referenced this pull request Jun 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants