-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[LoongArch] Emit error messages when using emulated TLS #92483
base: main
Are you sure you want to change the base?
[LoongArch] Emit error messages when using emulated TLS #92483
Conversation
Created using spr 1.3.5-bogner
@llvm/pr-subscribers-backend-loongarch Author: wanglei (wangleiat) ChangesSome developers are currently porting OpenHOS to LoongArch, which Full diff: https://github.com/llvm/llvm-project/pull/92483.diff 2 Files Affected:
diff --git a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
index fe2c613b1b30f..0b22ba50ee30f 100644
--- a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
@@ -934,6 +934,9 @@ LoongArchTargetLowering::lowerGlobalTLSAddress(SDValue Op,
GlobalAddressSDNode *N = cast<GlobalAddressSDNode>(Op);
assert(N->getOffset() == 0 && "unexpected offset in global node");
+ if (DAG.getTarget().useEmulatedTLS())
+ return LowerToTLSEmulatedModel(N, DAG);
+
bool IsDesc = DAG.getTarget().useTLSDESC();
switch (getTargetMachine().getTLSModel(N->getGlobal())) {
diff --git a/llvm/test/CodeGen/LoongArch/emutls.ll b/llvm/test/CodeGen/LoongArch/emutls.ll
new file mode 100644
index 0000000000000..56ec8e3715f38
--- /dev/null
+++ b/llvm/test/CodeGen/LoongArch/emutls.ll
@@ -0,0 +1,133 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
+; RUN: llc --mtriple=loongarch32 -emulated-tls -relocation-model=pic < %s \
+; RUN: | FileCheck -check-prefix=LA32 %s
+; RUN: llc --mtriple=loongarch64 -emulated-tls -relocation-model=pic < %s \
+; RUN: | FileCheck -check-prefix=LA64 %s
+
+@external_x = external thread_local global i32, align 8
+@y = thread_local global i8 7, align 2
+@internal_z = internal thread_local global i64 9, align 16
+
+define ptr @get_external_x() nounwind {
+; LA32-LABEL: get_external_x:
+; LA32: # %bb.0: # %entry
+; LA32-NEXT: addi.w $sp, $sp, -16
+; LA32-NEXT: st.w $ra, $sp, 12 # 4-byte Folded Spill
+; LA32-NEXT: pcalau12i $a0, %got_pc_hi20(__emutls_v.external_x)
+; LA32-NEXT: ld.w $a0, $a0, %got_pc_lo12(__emutls_v.external_x)
+; LA32-NEXT: bl %plt(__emutls_get_address)
+; LA32-NEXT: ld.w $ra, $sp, 12 # 4-byte Folded Reload
+; LA32-NEXT: addi.w $sp, $sp, 16
+; LA32-NEXT: ret
+;
+; LA64-LABEL: get_external_x:
+; LA64: # %bb.0: # %entry
+; LA64-NEXT: addi.d $sp, $sp, -16
+; LA64-NEXT: st.d $ra, $sp, 8 # 8-byte Folded Spill
+; LA64-NEXT: pcalau12i $a0, %got_pc_hi20(__emutls_v.external_x)
+; LA64-NEXT: ld.d $a0, $a0, %got_pc_lo12(__emutls_v.external_x)
+; LA64-NEXT: bl %plt(__emutls_get_address)
+; LA64-NEXT: ld.d $ra, $sp, 8 # 8-byte Folded Reload
+; LA64-NEXT: addi.d $sp, $sp, 16
+; LA64-NEXT: ret
+entry:
+ ret ptr @external_x
+}
+
+define ptr @get_y() nounwind {
+; LA32-LABEL: get_y:
+; LA32: # %bb.0: # %entry
+; LA32-NEXT: addi.w $sp, $sp, -16
+; LA32-NEXT: st.w $ra, $sp, 12 # 4-byte Folded Spill
+; LA32-NEXT: pcalau12i $a0, %got_pc_hi20(__emutls_v.y)
+; LA32-NEXT: ld.w $a0, $a0, %got_pc_lo12(__emutls_v.y)
+; LA32-NEXT: bl %plt(__emutls_get_address)
+; LA32-NEXT: ld.w $ra, $sp, 12 # 4-byte Folded Reload
+; LA32-NEXT: addi.w $sp, $sp, 16
+; LA32-NEXT: ret
+;
+; LA64-LABEL: get_y:
+; LA64: # %bb.0: # %entry
+; LA64-NEXT: addi.d $sp, $sp, -16
+; LA64-NEXT: st.d $ra, $sp, 8 # 8-byte Folded Spill
+; LA64-NEXT: pcalau12i $a0, %got_pc_hi20(__emutls_v.y)
+; LA64-NEXT: ld.d $a0, $a0, %got_pc_lo12(__emutls_v.y)
+; LA64-NEXT: bl %plt(__emutls_get_address)
+; LA64-NEXT: ld.d $ra, $sp, 8 # 8-byte Folded Reload
+; LA64-NEXT: addi.d $sp, $sp, 16
+; LA64-NEXT: ret
+entry:
+ ret ptr @y
+}
+
+define ptr @get_internal_z() nounwind {
+; LA32-LABEL: get_internal_z:
+; LA32: # %bb.0: # %entry
+; LA32-NEXT: addi.w $sp, $sp, -16
+; LA32-NEXT: st.w $ra, $sp, 12 # 4-byte Folded Spill
+; LA32-NEXT: pcalau12i $a0, %pc_hi20(__emutls_v.internal_z)
+; LA32-NEXT: addi.w $a0, $a0, %pc_lo12(__emutls_v.internal_z)
+; LA32-NEXT: bl %plt(__emutls_get_address)
+; LA32-NEXT: ld.w $ra, $sp, 12 # 4-byte Folded Reload
+; LA32-NEXT: addi.w $sp, $sp, 16
+; LA32-NEXT: ret
+;
+; LA64-LABEL: get_internal_z:
+; LA64: # %bb.0: # %entry
+; LA64-NEXT: addi.d $sp, $sp, -16
+; LA64-NEXT: st.d $ra, $sp, 8 # 8-byte Folded Spill
+; LA64-NEXT: pcalau12i $a0, %pc_hi20(__emutls_v.internal_z)
+; LA64-NEXT: addi.d $a0, $a0, %pc_lo12(__emutls_v.internal_z)
+; LA64-NEXT: bl %plt(__emutls_get_address)
+; LA64-NEXT: ld.d $ra, $sp, 8 # 8-byte Folded Reload
+; LA64-NEXT: addi.d $sp, $sp, 16
+; LA64-NEXT: ret
+entry:
+ ret ptr @internal_z
+}
+
+; UTC_ARGS: --disable
+
+; LA32: .data
+; LA32: .globl __emutls_v.y
+; LA32: .p2align 2
+; LA32-LABEL: __emutls_v.y:
+; LA32-NEXT: .word 1
+; LA32-NEXT: .word 2
+; LA32-NEXT: .word 0
+; LA32-NEXT: .word __emutls_t.y
+; LA32: .section .rodata,
+; LA32-LABEL: __emutls_t.y:
+; LA32-NEXT: .byte 7
+; LA32: .data
+; LA32: .p2align 2
+; LA32-LABEL: __emutls_v.internal_z:
+; LA32-NEXT: .word 8
+; LA32-NEXT: .word 16
+; LA32-NEXT: .word 0
+; LA32-NEXT: .word __emutls_t.internal_z
+; LA32: .section .rodata,
+; LA32-LABEL: __emutls_t.internal_z:
+; LA32-NEXT: .dword 9
+
+; LA64: .data
+; LA64: .globl __emutls_v.y
+; LA64: .p2align 3
+; LA64-LABEL: __emutls_v.y:
+; LA64-NEXT: .dword 1
+; LA64-NEXT: .dword 2
+; LA64-NEXT: .dword 0
+; LA64-NEXT: .dword __emutls_t.y
+; LA64: .section .rodata,
+; LA64-LABEL: __emutls_t.y:
+; LA64-NEXT: .byte 7
+; LA64: .data
+; LA64: .p2align 3
+; LA64-LABEL: __emutls_v.internal_z:
+; LA64-NEXT: .dword 8
+; LA64-NEXT: .dword 16
+; LA64-NEXT: .dword 0
+; LA64-NEXT: .dword __emutls_t.internal_z
+; LA64: .section .rodata,
+; LA64-LABEL: __emutls_t.internal_z:
+; LA64-NEXT: .dword 9
|
Hi @MaskRay
Otherwise, this issue will be reported as 'some symbols undefined' errors during the linking phase, which can be very confusing. |
Can we (and preferably also the OHOS porters) sort out and try to remove the emulated TLS usage in the OHOS codebase instead? At least we would know exactly why it is necessary if it eventually turns out to be the case. |
@yetist may be interested in this PR. |
I heard that currently some services in OHOS use coroutine which depends on emulated TLS, but I don't know the details. I also heard they plan to remove the dependency and switch to ELF TLS in future versions. So I prefer reporting error in somewhere (ether in clang or backend) if emulated TLS is used on LoongArch. |
Created using spr 1.3.5-bogner
Hi all: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Instead of an error for each TLS instance, emit it in TargetMachine ? |
Created using spr 1.3.5-bogner
I didn't find a way to emit an error message and return the error to the error handler. Either use |
Created using spr 1.3.5-bogner
Seems fine. report_fatal_error with false |
Does adding such test cases increase the testing time if useing |
No description provided.