Skip to content

Compiler generated main symbol has unavoidable pointless stack check  #14912

Closed
@huonw

Description

@huonw
#[no_split_stack]
#[start]
fn main(_: int, _: **u8) -> int {
    0
}

compiles to

    .text
    .file   "-.rs"
    .section    .text._ZN4main20he8340d7809f38c39eaa4v0.0E,"ax",@progbits
    .align  16, 0x90
    .type   _ZN4main20he8340d7809f38c39eaa4v0.0E,@function
_ZN4main20he8340d7809f38c39eaa4v0.0E:
    .cfi_startproc
    movabsq $0, %rax
    movq    %rdi, -8(%rsp)
    movq    %rsi, -16(%rsp)
    retq
.Ltmp0:
    .size   _ZN4main20he8340d7809f38c39eaa4v0.0E, .Ltmp0-_ZN4main20he8340d7809f38c39eaa4v0.0E
    .cfi_endproc

    .section    .text.main,"ax",@progbits
    .globl  main
    .align  16, 0x90
    .type   main,@function
main:
    .cfi_startproc
    cmpq    %fs:112, %rsp
    ja  .LBB1_0
    movabsq $8, %r10
    movabsq $0, %r11
    callq   __morestack
    retq
.LBB1_0:
    pushq   %rax
.Ltmp1:
    .cfi_def_cfa_offset 16
    callq   _ZN4main20he8340d7809f38c39eaa4v0.0E
    popq    %rdx
    retq
.Ltmp2:
    .size   main, .Ltmp2-main
    .cfi_endproc

    .section    ".note.GNU-stack","",@progbits

In particular the main function has a stack check, which can't be removed (there's no way to put a #[no_split_stack] on it: the compiler creates it automagically), and, (I think, I could easily be wrong) it's always pointless: when would the entry point of a program be overflowing the stack immediately?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions