• Willy Tarreau's avatar
    tools/nolibc: make compiler and assembler agree on the section around _start · 7f854858
    Willy Tarreau authored
    The out-of-block asm() statement carrying _start does not allow the
    compiler to know what section the assembly code is being emitted to,
    and there's no easy way to push/pop the current section and restore
    it. It sometimes causes issues depending on the include files ordering
    and compiler optimizations. For example if a variable is declared
    immediately before the asm() block and another one after, the compiler
    assumes that the current section is still .bss and doesn't re-emit it,
    making the second variable appear inside the .text section instead.
    Forcing .bss at the end of the _start block doesn't work either because
    at certain optimizations the compiler may reorder blocks and will make
    some real code appear just after this block.
    
    A significant number of solutions were attempted, but many of them were
    still sensitive to section reordering. In the end, the best way to make
    sure the compiler and assembler agree on the current section is to place
    this code inside a function. Here the function is directly called _start
    and configured not to emit a frame-pointer, hence to have no prologue.
    If some future architectures would still emit some prologue, another
    working approach consists in naming the function differently and placing
    the _start label inside the asm statement. But the current solution is
    simpler.
    
    It was tested with nolibc-test at -O,-O0,-O2,-O3,-Os for arm,arm64,i386,
    mips,riscv,s390 and x86_64.
    Signed-off-by: default avatarWilly Tarreau <w@1wt.eu>
    Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
    7f854858
arch-i386.h 10.2 KB