Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assembly ".set" directive emitting symbol

In some kernel-mode assembly source I have a line that looks like this:

; excerpt #1
.set __framesize, ROUND_TO_STACK(localvarsize)

(localvarsize is a parameter to a C-preprocessor macro, if you’re wondering.) I assume that __framesize is a compile-time variable that is usable in .if statements, and is then discarded. However, I find references to a symbol named __framesize in the symbol table and disassembly of my kernel. The symbol is defined (as output by nm -m) as such:

; excerpt #2
0000000000000000 (absolute) non-external __framesize

The usage of __framesize in compiler-generated assembly is as such:

; excerpt #3
movq %gs:__framesize, %rax
movq 0x140(%rax), %r15

Given what I understand of my compiler and my kernel, excerpt #3 should be emitted as movq %gs:0x140, %r15, and that code should work. (The code that is actually being emitted from the C as excerpt #3 is causing a triple fault on the second line.)

I have two questions:

  1. Should this __framesize symbol be emitted into my binary by the assembler when used in this fashion? If possible, how can I suppress it?
  2. Would this usage of __framesize cause a problem like what is discussed above?

I am using GAS assembler syntax and the Xcode 7.1.1 assembler, and a Mach-O output format, if it is useful.

like image 426
wjk Avatar asked Nov 20 '25 00:11

wjk


1 Answers

The GNU as manual says that .set modifies the value(i.e. address) and/or type of an existing symbol. It's synonymous with .equ, so it can be used to set/modify assembler macro variable, or to mess around with symbols which are also labels.

If __framesize is showing up in the object file, then it's probably declared somewhere else.

Try looking at the disassembly output, to see what really happened.

like image 140
Peter Cordes Avatar answered Nov 21 '25 17:11

Peter Cordes



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!