开发者

ld error: section not found for address

开发者 https://www.devze.com 2023-04-06 05:11 出处:网络
I am on Mac OS X 10.6.5 with XCode 3.2.4 and trying to compile/port a code base which compiles successfully on 10.5.A file contains hand-coded assembly code for exception handling.The compile stops wi

I am on Mac OS X 10.6.5 with XCode 3.2.4 and trying to compile/port a code base which compiles successfully on 10.5. A file contains hand-coded assembly code for exception handling. The compile stops with a ld error saying section not found for address 0x... What does this error message mean?

I am new to Mac OS X programming, but my search through the web and docs hasn't turned up much. A related question would be what to look for in trying to fix it. Thanks.

I'll include some original code and explain what I tried.

    .text

.align 1, 0x90
.globl _privateSnippetExecutorGeneral
_privateSnippetExecutorGeneral:
LFBg:
    movl    %esp,%ecx
    pushl   %ebp              # proper stack frame needed for exception handling
LCFIg0:
    movl    %esp,%ebp
LCFIg1:
    subl    $0x8,%esp         # padding + 32bit returnValue
    pushl   %esp              # 32bit &returnValue
    pushl   %ecx              # 32bit pCallStack
    pushl   %edx              # 32bit nVtableOffset
    pushl   %eax              # 32bit nFunctionIndex
    call    L_cpp_vtable_call$stub
    movl    16(%esp),%eax     # 32bit returnValue
    leave
    ret
LFEg:
    .long   .-_privateSnippetExecutorGeneral

There are 6 of the above assembly code blocks, virtually identical. I changed some 32-bit instructions to 64-bit counterparts and adjusted some stack manipulations. The call to L_cpp_vtable_call$stub is typical of the dynamic loader for 32-bit i386 operations. I've read docs from x86_64 and Apple but haven't seen a clear code sample of what it should be.

...

    .section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support
EH_frame1:
    .set L$set$frame1,LECIE1-LSCIE1
    .long   L$set$frame1      # length
LSCIE1:
    .long   0                 # CIE_ID
    .byte   1                 # version
    .ascii  "zPR\0"           # augmentation
    .byte   1                 # code_alignment_factor (.uleb128 1)
    .byte   0x7c              # data_alignment_factor (.sleb128 -4)
    .byte   8                 # return_address_register
    .byte   0x6               # augmentation size 7:
    .byte   0x9b              #  ???
    .long   L___gxx_personality_v0$non_lazy_ptr-.
    .byte   0x10
                              # initial_instructions:
    .byte   0x0C              #  DW_CFA_def_cfa %esp, 4
    .byte   5
    .byte   4
    .byte   0x88              #  DW_CFA_offset ret, 1
    .byte   1
    .align 2
LECIE1:

Above is the CIE section. The gxx_personality_v0 line also follows the typical dynamic loader code example for setting up the default exception handling routine. I compiled a hello world program to see what gcc spits out, and I changed it to

.long ___gxx_personality_v0+4@GOTPCREL

...

    .globl _privateSnippetExecutorGeneral.eh
_privateSnippetExecutorGeneral.eh:
LSFDEg:
    .set L$set$g1,LEFDEg-LASFDEg
    .long   L$set$g1          # length
LASFDEg:
    .long   LASFDEg-EH_frame1 # CIE_pointer
    .long   LFBg-.            # initial_location
    .long   LFEg-LFBg         # address_range
    .byte   0                 # augmentation size 0
                              # instructions:
    .byte   0x04              #  DW_CFA_advance_loc4
    .long   LCFIg0-LFBg
    .byte   0x0E              #  DW_CFA_def_cfa_offset 8
    .byte   8
    .byte   0x84              #  DW_CFA_offset %ebp, 2
    .byte   2
    .byte   0x04              #  DW_CFA_advance_loc4
    .long   LCFIg1-LCFIg0
    .byte   0x0D              #  DW_CFA_def_cfa_register %ebp
    .byte   4
    .align 2
LEFDEg:

Then there are 6 FDE sections (as above) corresponding to the assembly blocks. I did not modify them.

...

    .section __IMPORT,__jump_table,symbol_stubs,self_modifyi开发者_如何学运维ng_code+pure_instructions,5
L_cpp_vtable_call$stub:
    .indirect_symbol _cpp_vtable_call
    hlt ; hlt ; hlt ; hlt ; hlt                                                 
    .section __IMPORT,__pointers,non_lazy_symbol_pointers
L___gxx_personality_v0$non_lazy_ptr:
    .indirect_symbol ___gxx_personality_v0
    .long 0
    .constructor
    .destructor
    .align 1
    .subsections_via_symbols

Finally the stub sections. I haven't found too many docs, but my understanding is these sections are invalid for x86_64. The calling convention for dynamic loading no longer requires stubs but uses the Global Offset Table (GOT). So I commented out these sections. Are there things I should/not be doing? Any docs you can point me to?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号