<div dir="ltr">I don't think we should attempt to mangle symbols declared in assembly source files.  If you're writing assembly, you will need to handle ABI portability, including the _ prefix on win32 x86.<div>
<br></div><div>clang will run the C preprocessor for you if you use the .S file suffix (case matters).</div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 22, 2013 at 7:08 AM, ÂÞÓ¸Õ(Yonggang Luo) <span dir="ltr"><<a href="mailto:luoyonggang@gmail.com" target="_blank">luoyonggang@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">For example, I execute the following command sequences:<br><br>H:\CI\bld\compilers\musl\src\math\i386>type sqrt.s<br>

#.globl _sqrt<br>.global sqrt<br>#.type sqrt,@function<br>#_sqrt:<br>sqrt:   fldl 4(%esp)<br>


        fsqrt<br>        fstsw %ax<br>        sub $12,%esp<br>        fld %st(0)<br>        fstpt (%esp)<br>        mov (%esp),%ecx<br>        and $0x7ff,%ecx<br>        cmp $0x400,%ecx<br>        jnz 1f<br>        and $0x200,%eax<br>




        sub $0x100,%eax<br>        sub %eax,(%esp)<br>        fstp %st(0)<br>        fldt (%esp)<br>1:      add $12,%esp<br>        fstpl 4(%esp)<br>        fldl 4(%esp)<br>        ret<br><br>H:\CI\bld\compilers\musl\src\math\i386>type sqrt.c<br>




float __cdecl sqrt(float z)<br>{<br>    return 0.0;<br>}<br>H:\CI\bld\compilers\musl\src\math\i386>clang  -integrated-as -c -v --target=i686<br>-pc-win32 sqrt.s<br>clang version 3.4 (trunk)<br>Target: i686-pc-win32<br>




Thread model: posix<br> "C:\Program Files (x86)\LLVM 3.4.svn\bin\clang.exe" -cc1as -triple i686-pc-win3<br>2 -filetype obj -main-file-name sqrt.s -target-cpu pentium4 -fdebug-compilation-<br>dir "H:\\CI\\bld\\compilers\\musl\\src\\math\\i386" -dwarf-debug-producer clang<br>




version 3.4 (trunk) -o sqrt.o sqrt.s<br><br>H:\CI\bld\compilers\musl\src\math\i386>llvm-objdump -s -r -t sqrt.o<br><br>sqrt.o: file format COFF-i386<br><br>Contents of section .text:<br> 0000 dd442404 d9fa9bdf e083ec0c d9c0db3c  .D$............<<br>




 0010 248b0c24 81e1ff07 000081f9 00040000  $..$............<br> 0020 75122500 0200002d 00010000 290424dd  u.%....-....).$.<br> 0030 d8db2c24 83c40cdd 5c2404dd 442404c3  ..,$....\$..D$..<br>SYMBOL TABLE:<br>[ 0](sec  1)(fl 0x00)(ty   0)(scl   3) (nx 1) 0x00000000 .text<br>




AUX scnlen 0x40 nreloc 0 nlnno 0 checksum 0x0 assoc 1 comdat 0<br>[ 2](sec  1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 sqrt<br><br>H:\CI\bld\compilers\musl\src\math\i386>clang --target=i686-pc-win32 -c  sqrt.c<br>



sqrt.c:1:15: warning: incompatible redeclaration of library function 'sqrt'<br>
      [-Wincompatible-library-redeclaration]<br>float __cdecl sqrt(float z)<br>              ^<br>sqrt.c:1:15: note: 'sqrt' is a builtin with type 'double (double)'<br>1 warning generated.<br><br>H:\CI\bld\compilers\musl\src\math\i386>llvm-objdump -s -r -t sqrt.o<br>




<br>sqrt.o: file format COFF-i386<br><br>Contents of section .text:<br> 0000 5589e583 ec08f30f 1045080f 57c9f30f  U........E..W...<br> 0010 1145fcd9 eef30f11 4df883c4 085dc3    .E......M....].<br>SYMBOL TABLE:<br>[ 0](sec  1)(fl 0x00)(ty   0)(scl   3) (nx 1) 0x00000000 .text<br>




AUX scnlen 0x1f nreloc 0 nlnno 0 checksum 0x0 assoc 1 comdat 0<br>[ 2](sec -1)(fl 0x00)(ty   0)(scl   3) (nx 0) 0x00000001 @feat.00<br>[ 3](sec  1)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 _sqrt<br><br>H:\CI\bld\compilers\musl\src\math\i386><br>




H:\CI\bld\compilers\musl\src\math\i386>clang  -integrated-as -c -v --target=amd6<br>4-pc-win32 sqrt.s<br>clang version 3.4 (trunk)<br>Target: amd64-pc-win32<br>Thread model: posix<br> "C:\Program Files (x86)\LLVM 3.4.svn\bin\clang.exe" -cc1as -triple amd64-pc-win<br>




32 -filetype obj -main-file-name sqrt.s -target-cpu x86-64 -fdebug-compilation-d<br>ir "H:\\CI\\bld\\compilers\\musl\\src\\math\\i386" -dwarf-debug-producer clang v<br>ersion 3.4 (trunk) -o sqrt.o sqrt.s<br><br>




H:\CI\bld\compilers\musl\src\math\i386>llvm-objdump -s -r -t sqrt.o<br><br>sqrt.o: file format COFF-x86-64<br><br>Contents of section .text:<br> 0000 67dd4424 04d9fa9b dfe083ec 0cd9c067  g.D$...........g<br> 0010 db3c2467 8b0c2481 e1ff0700 0081f900  .<$g..$.........<br>




 0020 04000075 14250002 00002d00 01000067  ...u.%....-....g<br> 0030 290424dd d867db2c 2483c40c 67dd5c24  ).$..g.,$...g.\$<br> 0040 0467dd44 2404c3                      .g.D$..<br>SYMBOL TABLE:<br>[ 0](sec  1)(fl 0x00)(ty   0)(scl   3) (nx 1) 0x00000000 .text<br>




AUX scnlen 0x47 nreloc 0 nlnno 0 checksum 0x0 assoc 1 comdat 0<br>[ 2](sec  1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 sqrt<br><br>H:\CI\bld\compilers\musl\src\math\i386>clang --target=amd64-pc-win32 -c  sqrt.c<br>




sqrt.c:1:15: warning: incompatible redeclaration of library function 'sqrt'<br>      [-Wincompatible-library-redeclaration]<br>float __cdecl sqrt(float z)<br>              ^<br>sqrt.c:1:15: note: 'sqrt' is a builtin with type 'double (double)'<br>




1 warning generated.<br><br>H:\CI\bld\compilers\musl\src\math\i386>llvm-objdump -s -r -t sqrt.o<br><br>sqrt.o: file format COFF-x86-64<br><br>Contents of section .text:<br> 0000 554889e5 50f30f11 45fc0f57 c04883c4  UH..P...E..W.H..<br>




 0010 085dc3                               .].<br>SYMBOL TABLE:<br>[ 0](sec  1)(fl 0x00)(ty   0)(scl   3) (nx 1) 0x00000000 .text<br>AUX scnlen 0x13 nreloc 0 nlnno 0 checksum 0x0 assoc 1 comdat 0<br>[ 2](sec  1)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 sqrt<br>




<br>H:\CI\bld\compilers\musl\src\math\i386><div><br></div><div><b><br></b></div><div><b>My problem is:</b><br><br>Because C __cdecl calling convention vary on x86/amd64 architecture under win32. </div><div>for example, the sqrt function in is expressed as </div>




<div>float __cdecl sqrt(float)</div><div><br></div><div>but in the compiled object file, the final COFF symbol table:</div><div>on x86/win32(i686-pc-win32), it's named with "<b>_sqrt</b>" </div><div>on amd64/win32(amd64-pc-win32), it's named with "<b>sqrt</b>"</div>




<div><br></div><div><br></div><div><br></div><div>on linux(*-pc-linux), in ELF symbol table, it's named with "<b>sqrt</b>", </div><div><br></div><div><br></div><div>So I want to control the function name in assembly file, by the means of Assembly macros,</div>




<div>but I don't know LLVM-MC support which kinds of macros to control the assembly directives so that I can unified the assembly function name can match the c function name  in object symbol table under different CPU(x86/x64) and different OS(Win32/Linux/MacOS).</div>




<div>The simplest way is to duplicate the function name is to duplicate the function name in two form:</div><div>.globl _sqrt<br></div><div>.global sqrt<br>#.type sqrt,@function<br>_sqrt:<br>sqrt:   fldl 4(%esp)</div><div>




But that will leading redundant object symbol name.</div><div>besides, the<b> .type </b>didn't support under COFF symbol table, so how did I use assembly macro to comment it out when we are targeting COFF object but reserved when we are targeting ELF.</div>




<div>didn't know if Mach-O support for this directive.</div><span><font color="#888888"><div><br>-- <br>         ´ËÖÂ<br>Àñ<br>ÂÞÓ¸Õ<br>Yours<br>    sincerely,<br>Yonggang Luo</div></font></span></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div></div>