flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > Where's my decorator?? AMD64, g++

Author
Thread Post new topic Reply to topic
fpga



Joined: 22 Sep 2009
Posts: 36
fpga 28 Sep 2009, 18:44
First of all thank you Nikso for your example.
Code:
http://board.flatassembler.net/topic.php?t=5989
    

I inserted 'format ELF64' in the asm file and compiled with g++......
It worked great and I got the decorator for write() by typing
'nm cpp_part.o | grep write' as you instructed.

I used your example to write my own cpp_part and tried to get the decorator ready to write the asm_part.asm file.

new cpp_part.cpp
Code:
//inspired by http://board.flatassembler.net/topic.php?t=5989
#include <iostream>
using namespace std;

const char * fg_red = "\x1b[31m";
const char * bg_green = "\x1b[42m";
extern "C" int Write_ch(char ch, int x, int y, const char * fg, const char * bg); //was sum()

int main(){
   Write_ch('Z',10,20,fg_red,bg_green);
   return 0;
} 
    


When I type 'nm cpp_part.o | grep Write_ch' I get
Code:
U Write_ch
    

and when I type 'g++ -S -c cpp_part.cpp' I get
Code:
      .file   "cpp_part.cpp"
    .text
       .type   _Z41__static_initialization_and_destruction_0ii, @function
_Z41__static_initialization_and_destruction_0ii:
.LFB953:
  pushq   %rbp
.LCFI0:
 movq    %rsp, %rbp
.LCFI1:
   subq    $16, %rsp
.LCFI2:
    movl    %edi, -4(%rbp)
      movl    %esi, -8(%rbp)
      cmpl    $1, -4(%rbp)
        jne     .L3
 cmpl    $65535, -8(%rbp)
    jne     .L3
 movl    $_ZStL8__ioinit, %edi
       call    _ZNSt8ios_base4InitC1Ev
     movl    $_ZNSt8ios_base4InitD1Ev, %edi
      movl    $__dso_handle, %edx
 movl    $_ZStL8__ioinit, %esi
       call    __cxa_atexit
.L3:
    leave
       ret
.LFE953:
 .size   _Z41__static_initialization_and_destruction_0ii, .-_Z41__static_initialization_and_destruction_0ii
  .type   _GLOBAL__I_fg_red, @function
_GLOBAL__I_fg_red:
.LFB954:
      pushq   %rbp
.LCFI3:
 movq    %rsp, %rbp
.LCFI4:
   movl    $65535, %esi
        movl    $1, %edi
    call    _Z41__static_initialization_and_destruction_0ii
     leave
       ret
.LFE954:
 .size   _GLOBAL__I_fg_red, .-_GLOBAL__I_fg_red
      .section        .ctors,"aw",@progbits
     .align 8
    .quad   _GLOBAL__I_fg_red
   .text
.globl main
        .type   main, @function
main:
.LFB952:
        pushq   %rbp
.LCFI5:
 movq    %rsp, %rbp
.LCFI6:
   subq    $16, %rsp
.LCFI7:
    movb    $90, -1(%rbp)
       movl    $10, -8(%rbp)
       movl    $20, -12(%rbp)
      movq    bg_green(%rip), %rax
        movq    fg_red(%rip), %rcx
  movsbl  -1(%rbp),%edi
       movl    -12(%rbp), %edx
     movl    -8(%rbp), %esi
      movq    %rax, %r8
   call    Write_ch
    movl    $0, %eax
    leave
       ret
.LFE952:
 .size   main, .-main
.globl fg_red
       .section        .rodata
.LC0:
        .string "\033[31m"
   .data
       .align 8
    .type   fg_red, @object
     .size   fg_red, 8
fg_red:
    .quad   .LC0
.globl bg_green
     .section        .rodata
.LC1:
        .string "\033[42m"
   .data
       .align 8
    .type   bg_green, @object
   .size   bg_green, 8
bg_green:
        .quad   .LC1
        .local  _ZStL8__ioinit
      .comm   _ZStL8__ioinit,1,1
  .weakref        _ZL20__gthrw_pthread_oncePiPFvvE,pthread_once
       .weakref        _ZL27__gthrw_pthread_getspecificj,pthread_getspecific
       .weakref        _ZL27__gthrw_pthread_setspecificjPKv,pthread_setspecific
    .weakref        _ZL22__gthrw_pthread_createPmPK14pthread_attr_tPFPvS3_ES3_,pthread_create
   .weakref        _ZL22__gthrw_pthread_cancelm,pthread_cancel
 .weakref        _ZL26__gthrw_pthread_mutex_lockP15pthread_mutex_t,pthread_mutex_lock
        .weakref        _ZL29__gthrw_pthread_mutex_trylockP15pthread_mutex_t,pthread_mutex_trylock
  .weakref        _ZL28__gthrw_pthread_mutex_unlockP15pthread_mutex_t,pthread_mutex_unlock
    .weakref        _ZL26__gthrw_pthread_mutex_initP15pthread_mutex_tPK19pthread_mutexattr_t,pthread_mutex_init
 .weakref        _ZL30__gthrw_pthread_cond_broadcastP14pthread_cond_t,pthread_cond_broadcast
 .weakref        _ZL25__gthrw_pthread_cond_waitP14pthread_cond_tP15pthread_mutex_t,pthread_cond_wait
 .weakref        _ZL26__gthrw_pthread_key_createPjPFvPvE,pthread_key_create
  .weakref        _ZL26__gthrw_pthread_key_deletej,pthread_key_delete
 .weakref        _ZL30__gthrw_pthread_mutexattr_initP19pthread_mutexattr_t,pthread_mutexattr_init
    .weakref        _ZL33__gthrw_pthread_mutexattr_settypeP19pthread_mutexattr_ti,pthread_mutexattr_settype
     .weakref        _ZL33__gthrw_pthread_mutexattr_destroyP19pthread_mutexattr_t,pthread_mutexattr_destroy
      .section        .eh_frame,"a",@progbits
.Lframe1:
  .long   .LECIE1-.LSCIE1
.LSCIE1:
     .long   0x0
 .byte   0x1
.globl __gxx_personality_v0
  .string "zPR"
     .uleb128 0x1
        .sleb128 -8
 .byte   0x10
        .uleb128 0x6
        .byte   0x3
 .long   __gxx_personality_v0
        .byte   0x3
 .byte   0xc
 .uleb128 0x7
        .uleb128 0x8
        .byte   0x90
        .uleb128 0x1
        .align 8
.LECIE1:
.LSFDE1:
    .long   .LEFDE1-.LASFDE1
.LASFDE1:
   .long   .LASFDE1-.Lframe1
   .long   .LFB953
     .long   .LFE953-.LFB953
     .uleb128 0x0
        .byte   0x4
 .long   .LCFI0-.LFB953
      .byte   0xe
 .uleb128 0x10
       .byte   0x86
        .uleb128 0x2
        .byte   0x4
 .long   .LCFI1-.LCFI0
       .byte   0xd
 .uleb128 0x6
        .align 8
.LEFDE1:
.LSFDE3:
    .long   .LEFDE3-.LASFDE3
.LASFDE3:
   .long   .LASFDE3-.Lframe1
   .long   .LFB954
     .long   .LFE954-.LFB954
     .uleb128 0x0
        .byte   0x4
 .long   .LCFI3-.LFB954
      .byte   0xe
 .uleb128 0x10
       .byte   0x86
        .uleb128 0x2
        .byte   0x4
 .long   .LCFI4-.LCFI3
       .byte   0xd
 .uleb128 0x6
        .align 8
.LEFDE3:
.LSFDE5:
    .long   .LEFDE5-.LASFDE5
.LASFDE5:
   .long   .LASFDE5-.Lframe1
   .long   .LFB952
     .long   .LFE952-.LFB952
     .uleb128 0x0
        .byte   0x4
 .long   .LCFI5-.LFB952
      .byte   0xe
 .uleb128 0x10
       .byte   0x86
        .uleb128 0x2
        .byte   0x4
 .long   .LCFI6-.LCFI5
       .byte   0xd
 .uleb128 0x6
        .align 8
.LEFDE5:
    .ident  "GCC: (Ubuntu 4.3.3-5ubuntu4) 4.3.3"
  .section        .note.GNU-stack,"",@progbits
    


I expected a decorator resembling that in the following line (from Nikso's example) that I could replace it with.
Code:
extrn "_Z5writePc" as write
    

but I don't see anything like it.
Am I doing something wrong?
Post 28 Sep 2009, 18:44
View user's profile Send private message Reply with quote
fpga



Joined: 22 Sep 2009
Posts: 36
fpga 29 Sep 2009, 08:35
I woke up wondering if I'd see a more representative decorator if I completed the function implementation in c++ before replacing it with an asm one i.e. creating a fully functional program without asm.

I did this and 'nm cpp_part.o | grep Write_ch' now gives...
Code:
_Z8Write_chciiPKcS0_
    

That's more like what I expected to see!
What threw me was that the object file compiled without complaint before.

Re the decorator's parameter representation,
I can see...
how 'cii' after 'Write_ch' equates to char, integer, integer
but don't understand...
how 'PKcS0_' equates to const char *, const char *.
Can someone explain this please?
Post 29 Sep 2009, 08:35
View user's profile Send private message Reply with quote
r22



Joined: 27 Dec 2004
Posts: 805
r22 13 Oct 2009, 20:30
G++ has poor documentation regarding the way it mangles.

PKcS0_
P = Pointer
K = Constant
c = char
S = Signed char / static
O = rvalue reference ...
_ = ... to last defined argument (aka the PKc or PKcS)
Post 13 Oct 2009, 20:30
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.