objcopy: fails to copy a particular section (`.rodata' required but not present […])

前端 未结 1 792
清酒与你
清酒与你 2021-01-23 14:26

I compiled a Hello World C file and need just one section (only the hello world function) of it.

The compiled file has the format elf32-i386 and contains 4 sections:

相关标签:
1条回答
  • 2021-01-23 15:24

    First, you mentioned you need only the the .text section - for the purpose of runtime execution? That is not right: if that hello functions has strings hardcoded inside, all these strings will be located inside .rodata section, so are u going to ignore this section?

    .eh_frame is for debugger, and .comment i think is not needed, but .data is also needed.

    Another thing is the relocation table - if the fucntion is to be dynamically loaded into some arbitrary memory region, then lots of area INSIDE the function may need to be patched.....check objdump -r of your ELF to find out if there is any relocation entries. if not, u are safe.

    Also, anything inside your function declared as "const" will also go into the .rodata section - global data of course. Variables or constants local to the function are on the stack. And all global data are located inside .data section.

    But coming back to the original error, the reason is because the example 3 in the original URL does not have cross-referencing (the .interp section) and therefore objdump -s will not have error. Your case, .text does have cross-referencing to .rodata section, but is not available after you have extracted just the .text section out.

    0 讨论(0)
提交回复
热议问题