What does% P mean in gcc inline assembly

In the linux/arch/x86/boot/main.c kernel linux/arch/x86/boot/main.c I found a piece of asm inline code:

 asm("leal %P1(%%esp),%0" : "=r" (stack_end) : "i" (-STACK_SIZE)); 

This piece of code is pretty simple, but %P1 confused me. I checked several assembly language lessons, but found nothing about it.

So can someone give me some clues about this?

+7
assembly
source share
1 answer

The output modifier P unofficially documented in a comment in gcc / config / i386 / i386.md :

 ;; The special asm out single letter directives following a '%' are: ... ;; P -- if PIC, print an @PLT suffix. ;; p -- print raw symbol name. 

The top stanza modifier P is probably not the one needed here, but when it does not compile a PIC (position-independent code), it acts like a string modifier P The goal is to prevent the compiler from emitting an operand using a format commonly used for immediate values โ€‹โ€‹that does not work here. As David Wolferd said, it would be better to use the c modifier, which is documented and specifically designed to handle instantaneous values. Keep in mind that this code was probably written before modifying the c modifier, since for a long time, none of the modifiers were documented.

Given that the built-in assembly statement is executed only once at boot time, performance does not matter, so I would not try to be smart with LEA. You can completely avoid operand modifiers with something simple:

  char *stack_pointer; asm ("mov %%esp, %0" : "=r" (stack_pointer)); stack_end = stack_pointer - STACK_SIZE; 
+3
source share

All Articles