Skip to content
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

[SSP] Accessing __stack_chk_guard when using LTO #66535

Merged
merged 2 commits into from
Sep 19, 2023

Conversation

wolfy1961
Copy link
Collaborator

This is a pre-commit test of accessing the variable __stack_chk_guard when the static relocation model is imposed on a module compiled with pic enabled. It confirms issue #64999.

The intent is to update this test with the fix for the aforementioned issue.

This is a pre-commit test of accessing the variable __stack_chk_guard
when the static relocation model is imposed on a module compiled with pic enabled.
@llvmbot llvmbot added the LTO Link time optimization (regular/full LTO or ThinLTO) label Sep 15, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Sep 15, 2023

@llvm/pr-subscribers-lto

Changes

This is a pre-commit test of accessing the variable __stack_chk_guard when the static relocation model is imposed on a module compiled with pic enabled. It confirms issue #64999.

The intent is to update this test with the fix for the aforementioned issue.

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

1 Files Affected:

  • (added) llvm/test/LTO/ARM/ssp-static-reloc.ll (+40)
diff --git a/llvm/test/LTO/ARM/ssp-static-reloc.ll b/llvm/test/LTO/ARM/ssp-static-reloc.ll
new file mode 100644
index 000000000000000..ca32505996b8656
--- /dev/null
+++ b/llvm/test/LTO/ARM/ssp-static-reloc.ll
@@ -0,0 +1,40 @@
+; Confirm that we do generate one too many indirections accessing the stack guard
+; variable, when the relocation model is static.
+; This is preparation for the fix. 
+;
+; RUN: llvm-as < %s > %t.bc
+; RUN: llvm-lto -O0 -relocation-model=static -o %t.o %t.bc
+; RUN: llvm-objdump -d -r %t.o | FileCheck %s
+
+target triple = "armv4t-unknown-unknown"
+
+define arm_aapcscc i8 @foo() #0 {
+entry:
+  %arr = alloca [200 x i8], align 1
+  call void @llvm.memset.p0.i32(ptr align 1 %arr, i8 0, i32 200, i1 false)
+  %arrayidx = getelementptr inbounds [200 x i8], ptr %arr, i32 0, i8 5
+  %0 = load i8, ptr %arrayidx, align 1
+  ret i8 %0
+}
+
+; CHECK:      <foo>:
+; CHECK:      [[#%x,CURPC:]]:{{.*}} ldr r[[REG1:[0-9]+]], [pc, #0x[[#%x,OFFSET:]]]
+; CHECK-NEXT: ldr r[[REG2:[0-9]+]], [r[[REG1]]]
+; CHECK-NEXT: ldr r[[REG3:[0-9]+]], [r[[REG2]]]
+; CHECK-NEXT: str r[[REG3]],
+; CHECK:      [[#CURPC + OFFSET + 8]]:{{.*}}.word
+; CHECK-NEXT: R_ARM_ABS32 __stack_chk_guard
+
+declare void @llvm.memset.p0.i32(ptr nocapture writeonly, i8, i32, i1 immarg)
+
+define arm_aapcscc i32 @main() {
+entry:
+  %call = call arm_aapcscc i8 @foo()
+  %conv = zext i8 %call to i32
+  ret i32 %conv
+}
+
+attributes #0 = { noinline nounwind optnone sspstrong }
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 8, !"PIC Level", i32 2}

llvm/test/LTO/ARM/ssp-static-reloc.ll Show resolved Hide resolved
attributes #0 = { noinline nounwind optnone sspstrong }

!llvm.module.flags = !{!0}
!0 = !{i32 8, !"PIC Level", i32 2}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is all this meta data necessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need sspstrong and PIC Level to demonstrate the problem, i.e. the guard variable is accessed like we're generating PIC code even though there is no GOT.

Copy link
Collaborator

@RKSimon RKSimon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wolfy1961 wolfy1961 merged commit 47c5734 into llvm:main Sep 19, 2023
2 checks passed
@wolfy1961 wolfy1961 deleted the ssp-stack-check-test branch September 19, 2023 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LTO Link time optimization (regular/full LTO or ThinLTO)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants