Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCC assembly output: Get variables declared 'extern'

Tags:

c

gcc

assembly

I am creating assembly code from C code with gcc.exe -S -masm=intel -o filename.S filename.c. I declared some variables as extern to allow later linking. I expected something like extern variable in nasm, but the variable is never mentioned in the assembly file.

Is there a way to check if a variable is extern or not? Or can I force gcc to add this information to the assembly file?

like image 998
kaetzacoatl Avatar asked Nov 25 '25 13:11

kaetzacoatl


1 Answers

If your extern variable is not mentioned in the assembly file, you're likely not using this variable. However, even if you were using it, you wouldn't see anything like .extern varname in assembly as well. GNU assembler treats all undefined symbols as external ones. GCC knows this and doesn't emit .extern directives. So look for, uhm, "PC-relative" variables (like in mov eax, DWORD PTR varname[rip]). That's your extern vars.

like image 110
Nikita Kakuev Avatar answered Nov 28 '25 02:11

Nikita Kakuev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!