[PATCH] Don't access items in .sdata section using gp-relative addressing when target is NaCl.
Sasa Stankovic
Sasa.Stankovic at imgtec.com
Tue Jun 10 06:14:06 PDT 2014
> Presumably the reason that UseSmallSection is disabled for Linux is that LLVM is assuming that it might be being used with Gold?
It isn't related to Gold because apart from PNaCl, MIPS Gold is not used anywhere else; MIPS Gold isn't even committed to the FSF binutils - the patch is still in review on binutils mailing list.
I suppose that the reason why it's disabled in Linux is because gp-relative addressing can only address 64K area (MIPS has 16-bit load/store offsets). That's probably why it's never used for PIC code (both Linux and non-Linux), because in PIC code .got section is also accessed using gp-relative addressing, so that leaves even less space for data items to be accessed using gp-relative addressing.
> If you don't explain this in the commit message or in the code, how would someone reading the
> source code know the reason for making UseSmallSection conditional on !isTargetNaCl()? How
> would someone maintaining the code know whether the !isTargetNaCl() check could be removed?
>
> I think you should add a comment explaining this in the code.
When I said that I was not sure whether this should be in the commit message I was referring to Gold (I think we should not mention Gold in LLVM code or commit message).
I updated the patch with the comment that in NaCl we disable gp-relative addressing because it can address 64K area only.
http://reviews.llvm.org/D4069
Files:
lib/Target/Mips/MipsSubtarget.cpp
test/CodeGen/Mips/nacl-small-section.ll
Index: lib/Target/Mips/MipsSubtarget.cpp
===================================================================
--- lib/Target/Mips/MipsSubtarget.cpp
+++ lib/Target/Mips/MipsSubtarget.cpp
@@ -153,7 +153,9 @@
// Set UseSmallSection.
// TODO: Investigate the IsLinux check. I suspect it's really checking for
// bare-metal.
- UseSmallSection = !IsLinux && (RM == Reloc::Static);
+ // We disable gp-relative addressing for NaCl. gp-relative addressing can
+ // address 64K area only.
+ UseSmallSection = !IsLinux && !isTargetNaCl() && (RM == Reloc::Static);
}
bool
Index: test/CodeGen/Mips/nacl-small-section.ll
===================================================================
--- test/CodeGen/Mips/nacl-small-section.ll
+++ test/CodeGen/Mips/nacl-small-section.ll
@@ -0,0 +1,18 @@
+; RUN: llc -filetype=asm -mtriple=mipsel-none-nacl -relocation-model=static \
+; RUN: < %s | FileCheck %s
+
+
+ at x = global i32 1, align 4
+
+define i32 @test1() {
+ %1 = load i32* @x, align 4
+ ret i32 %1
+
+
+; CHECK-LABEL: test1
+
+; Check that in NaCl the items in .sdata secton are not accessed using
+; gp-relative addressing.
+
+; CHECK-NOT: %gp_rel(x)($gp)
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4069.10273.patch
Type: text/x-patch
Size: 1191 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140610/a38b7c7d/attachment.bin>
More information about the llvm-commits
mailing list