1

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)

1 Answer 1

3

You can make your section directive state explicitly that the section's contents are executable:

section .stage1_main exec

and you might also want to insist on 16-byte alignment (which nasm will do automatically for the .text section):

section .stage1_main exec align=16

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.