1

I am converting some code from Intel Syntax to AT&T syntax.

I have the folowing code, that loads a GDT, and does a far jump using the loaded GDT, defined in the .rodata section.

.global start
.extern long_mode_start

.section .text
start:
        lgdt    (gdt64.pointer)
        jmp     $gdt64.code, $long_mode_start
.section .rodata
gdt64:
        .quad 0 # zero entry
.equ gdt64.code, 0x08
        .quad (1<<43) | (1<<44) | (1<<47) | (1<<53) # code segment
gdt64.pointer:
        .word . - gdt64 - 1
        .quad gdt64

The problem is that I have to put the .rodata section before the .text section on the file, otherwise the assembler complains: Error: can't handle non absolute segment in `jmp', which makes me think that it's assuming it is an external symbol, even though I didn't say so.

Is there any way to make this work with the .rodata section in any place in the file, or does it really have to be before the .text section?

SamFF
  • 203
  • 1
  • 7
  • 3
    GNU assembler assumes symbols are external by default (incidentally that means the `.extern long_mode_start` is not required). You do not need to move the `.rodata` section, only the `.equ gdt64.code, 0x08` which is not part of a section since it is just an assembler directive. – Jester Aug 01 '22 at 12:00
  • @Jester What if I had ```.equ gdt64.code, . - gdt64``` on the ```.rodata``` section? I hat to move the whole section right? – SamFF Aug 01 '22 at 12:32
  • 1
    Yes, because `.` refers to the current position which does depend on the location. – Jester Aug 01 '22 at 12:34
  • 2
    Even if you replace the `.` with a symbol, the assembler needs to see it first, according to my tests. – Jester Aug 01 '22 at 12:40
  • Yeah, thats what I was thinking. Thank you! – SamFF Aug 01 '22 at 12:54
  • Highly related: [Distinguishing memory from constant in GNU as .intel\_syntax](https://stackoverflow.com/q/39355188) including an AT&T syntax section at the end. (With a different use that actually assembles either way so we can see what the assembler was thinking.) Assuming you want to keep the `0x08` constant definition next to the other parts of `.rodata` just for maintenance reasons, yes, it seems you need to move it ahead of the code that uses it. – Peter Cordes Aug 01 '22 at 19:22

0 Answers0