News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Link to a static lib in .a format

Started by jj2007, August 08, 2017, 08:05:36 AM

Previous topic - Next topic

jj2007

Whatever I tried, it's always "unresolved symbol" for the linker. Any idea if it's possible at all?
jj

include \masm32\include\masm32rt.inc
includelib C:\TDM-GCC-32\lib\gcc\mingw32\4.9.2\libgcc.a

.code
start:
  exit
;   mulvsi3 PROTO :REAL8, :REAL8
  ExternDef mulvsi3:DWORD
  ; mulvsi3 PROTO :DWORD, :DWORD
  call mulvsi3

end start

TWell

Could be possible with polink to link function __mulvsi3 ;)

nidud

#2
deleted

jj2007

Yep, that works, thanks to both of you :t

Btw does somebody know how the linker knows the arg list? With a wrong PROTO, the linker throws an error (and rightly so); but I can't see (using PeView) that information "attached" e.g. to the _acoshq in the offset table of the C:\TDM-GCC-32\lib\gcc\mingw32\4.9.2\libquadmath.a ::)

TWell

linker see only symbols, no args?
in i386:
_acoshq is a __cdecl symbol. Type = DT_FUNCTION, Storage Class = IMAGE_SYM_CLASS_EXTERNAL
__stdcall function have declaration _function@x, where x is parameters size.

jj2007

OK, I see:

  __mulvsi3 proto c :REAL4      ; wrong but works because it's C
  call __mulvsi3

Thanks :icon14:

aw27

Quote from: jj2007 on August 09, 2017, 01:20:37 AM
; wrong but works because it's C

It will not happen with C++, though.  :greensml:

TWell

If someone don't want to use libgcc.a, llvm offers some functions in different licence.
See llvm builtins

Vortex

Extracting and disassembling the module  __mulvsi3 :


C:\TDM-GCC-32\lib\gcc\mingw32\5.1.0>md temp

C:\TDM-GCC-32\lib\gcc\mingw32\5.1.0>cd temp

C:\TDM-GCC-32\lib\gcc\mingw32\5.1.0\temp>\PellesC\bin\polib.exe /EXPLODE ..\libgcc.a
POLIB: fatal error: The filename, directory name, or volume label syntax is incorrect.

C:\TDM-GCC-32\lib\gcc\mingw32\5.1.0\temp>H:\masm32\bin\objconv.exe -fmasm _mulvsi3.o Disasm-mulvsi3.asm

Input file: _mulvsi3.o, output file: Disasm-mulvsi3.asm
Converting from COFF32 to Disassembly32

  7 Debug sections removed
  0 Exception sections removed


.386
option dotname
.model flat

public ___mulvsi3

extern _abort: near

_text   SEGMENT PARA PUBLIC 'CODE'

_text   LABEL NEAR

___mulvsi3 LABEL NEAR
        push    ebx
        sub     esp, 8
        mov     eax, dword ptr [esp+14H]
        imul    dword ptr [esp+10H]
        mov     ecx, eax
        sar     ecx, 31
        cmp     ecx, edx
        jnz     ?_001
        add     esp, 8
        pop     ebx
        ret

?_001   LABEL NEAR
        call    _abort
        nop

_text   ENDS

_data   SEGMENT DWORD PUBLIC 'DATA'

_data   ENDS

.bss    SEGMENT DWORD PUBLIC 'BSS'

.bss    ENDS

.text.unlikely SEGMENT DWORD PUBLIC 'CODE'

.text.unlikely ENDS

.rdata$zzz SEGMENT DWORD PUBLIC 'CONST'

        db 47H, 43H, 43H, 3AH, 20H, 28H, 74H, 64H
        db 6DH, 2DH, 31H, 29H, 20H, 35H, 2EH, 31H
        db 2EH, 30H, 00H, 00H

.rdata$zzz ENDS

END


Simplifying the code :

.386
.model flat,stdcall

PUBLIC mulvsi3

.data

mulvsi3 dd ?

.code

__mulvsi3 PROC C x:DWORD,y:DWORD

    mov     eax,y
    imul    x
    mov     ecx,eax
    sar     ecx,31
    cmp     ecx, edx
    jnz     _exit
    ret
   
_exit:

    mov     mulvsi3,1  ; code to simulate
    ret                ; the abort case

__mulvsi3 ENDP

END


Testing the function :

include \masm32\include\masm32rt.inc

__mulvsi3 PROTO C :DWORD,:DWORD

EXTERN mulvsi3:DWORD

.data

msg         db 'Result = %d',0

.code

start:

    invoke  __mulvsi3,36,24

    invoke  crt_printf,ADDR msg,eax

    invoke  ExitProcess,0

END start