Skip to content

Commit 872dbfa

Browse files
lzufalconwtarreau
authored andcommitted
tools/nolibc: silence ppc64 compile warnings
Silence the following warnings reported by the new -Wall -Wextra options with pure assembly code. In file included from sysroot/powerpc/include/stdio.h:13, from nolibc-test.c:13: sysroot/powerpc/include/arch.h: In function '_start': sysroot/powerpc/include/arch.h:192:32: warning: unused variable 'r2' [-Wunused-variable] 192 | register volatile long r2 __asm__ ("r2") = (void *)&TOC - (void *)_start; | ^~ sysroot/powerpc/include/arch.h:187:97: warning: optimization may eliminate reads and/or writes to register variables [-Wvolatile-register-var] 187 | void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void) | ^~~~~~ Since only elfv2 ABI requires to save the TOC/GOT pointer to r2 register, when using elfv1 ABI, the old C code is simply ignored by the compiler, but the compiler can not ignore the inline assembly code and will introduce build failure or running segfaults. So, let's further only add the new assembly code for elfv2 ABI with the checking of _CALL_ELF == 2. Link: https://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi.pdf Link: https://www.llvm.org/devmtg/2014-04/PDFs/Talks/Euro-LLVM-2014-Weigand.pdf Signed-off-by: Zhangjin Wu <falcon@tinylab.org> Signed-off-by: Willy Tarreau <w@1wt.eu>
1 parent 418c846 commit 872dbfa

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

tools/include/nolibc/arch-powerpc.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,17 @@
187187
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
188188
{
189189
#ifdef __powerpc64__
190-
/* On 64-bit PowerPC, save TOC/GOT pointer to r2 */
191-
extern char TOC __asm__ (".TOC.");
192-
register volatile long r2 __asm__ ("r2") = (void *)&TOC - (void *)_start;
190+
#if _CALL_ELF == 2
191+
/* with -mabi=elfv2, save TOC/GOT pointer to r2
192+
* r12 is global entry pointer, we use it to compute TOC from r12
193+
* https://www.llvm.org/devmtg/2014-04/PDFs/Talks/Euro-LLVM-2014-Weigand.pdf
194+
* https://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi.pdf
195+
*/
196+
__asm__ volatile (
197+
"addis 2, 12, .TOC. - _start@ha\n"
198+
"addi 2, 2, .TOC. - _start@l\n"
199+
);
200+
#endif /* _CALL_ELF == 2 */
193201

194202
__asm__ volatile (
195203
"mr 3, 1\n" /* save stack pointer to r3, as arg1 of _start_c */

0 commit comments

Comments
 (0)