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

inefficient segment register relative access #62482

Closed
nickdesaulniers opened this issue May 1, 2023 · 3 comments
Closed

inefficient segment register relative access #62482

nickdesaulniers opened this issue May 1, 2023 · 3 comments
Labels
backend:X86 duplicate Resolved as duplicate

Comments

@nickdesaulniers
Copy link
Member

nickdesaulniers commented May 1, 2023

consider the following code:

// -fstack-protector-strong -O2 -mstack-protector-guard-reg=gs -mstack-protector-guard-symbol=__stack_chk_guard -fno-pie
void foo (int*);

void bar (int x) {
    int y [x];
    foo(y);
}

clang generates:

        movq    __stack_chk_guard@GOTPCREL(%rip), %rbx
        movq    %gs:(%rbx), %rax
        movq    %rax, -16(%rbp)

to read the stack canary into the relevant stack slot. GCC generates a much nicer:

        movq    %gs:__stack_chk_guard(%rip), %rax
        movq    %rax, -8(%rbp)

Can we do better? (15B vs 12B per function with a stack protector)

@llvmbot
Copy link
Collaborator

llvmbot commented May 1, 2023

@llvm/issue-subscribers-backend-x86

@nickdesaulniers
Copy link
Member Author

This looks fixed by @MaskRay 's https://reviews.llvm.org/D150841 (was that intentional)? (without specifying -f[no-]direct-access-external-data).

	movq	%gs:__stack_chk_guard(%rip), %rax
	movq	%rax, -8(%rbp)

@MaskRay
Copy link
Member

MaskRay commented May 23, 2023

Duplicate of #60116

(-fstack-protector-strong -fno-PIE -mstack-protector-guard-reg=gs -mstack-protector-guard-symbol=__stack_chk_guard)

Clang's GOT-indirect code sequence for no-PIC avoids a copy relocation if __stack_chk_guard turns out to be defined by a shared object (say, libc.so.6).

@MaskRay MaskRay closed this as not planned Won't fix, can't repro, duplicate, stale May 23, 2023
@EugeneZelenko EugeneZelenko added the duplicate Resolved as duplicate label May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:X86 duplicate Resolved as duplicate
Projects
None yet
Development

No branches or pull requests

4 participants