I’m tring to assemble the following code using Nasm:
section .stage1_main
extern stage1_get_stage2_addr
global stage1_main
stage1_main:
sub rsp, 0x8
call stage1_get_stage2_addr
cmp rax, -1
jz error
add rsp, 0x8
push stage1_main
jmp rax
error:
ret
.stage1_main is a new section that I defined. the probelm is that Nasm define it as a DATA section
objdump -h main.o
main.o: file format elf64-x86-64
Sections:
Idx Name Size VMA LMA File off Algn
0 .stage1_main 0000001b 0000000000000000 0000000000000000 000001c0 2**0
CONTENTS, ALLOC, LOAD, RELOC, READONLY, DATA
I need a code section…
is there a way to define my section as a CODE section (like .text)
You can make your
sectiondirective state explicitly that the section’s contents are executable:section .stage1_main execand you might also want to insist on 16-byte alignment (which
nasmwill do automatically for the.textsection):section .stage1_main exec align=16