Mail Archives: cygwin/2014/04/07/10:36:40
--vbzKE9fGfpHIBC6T
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
On Apr 7 14:02, Jean-Pierre Flori wrote:
> Le Mon, 07 Apr 2014 13:28:19 +0000, Jean-Pierre Flori a =C3=A9crit=C2=A0:
>=20
> > Le Mon, 07 Apr 2014 13:57:30 +0200, Corinna Vinschen a =C3=A9crit=C2=A0:
> >=20
> >> On Apr 7 11:50, Jean-Pierre Flori wrote:
> >>> Le Mon, 07 Apr 2014 13:30:27 +0200, Corinna Vinschen a =C3=A9crit=C2=
=A0:
> >>> >=20
> >>> > I'm sorry, but I don't know how this works exactly. The nm prefix
> >>> > is only added for external references, not for inlined functions,
> >>> > but I don't know the gory details. You may be better off to ask on
> >>> > the gcc mailing list.
> >>> >=20
> >>> No problem, I've already learned tons of stuff thanks to your help.
> >>> I've just posted on gcc-help.
> >>> http://gcc.gnu.org/ml/gcc-help/2014-04/msg00024.html
> >>=20
> >> Thanks. A simple testcase would still be nice, of course.
> >>=20
> >>=20
> > Sure, but it seems the issue is that I cannot get the __nm_ prefix when
> > I elaborate on a minimal problem like you did.
> >=20
> > I'll still try to get something this afternoon.
> I think I got something:
> $ cat > lib.c <<EOF
> #include <stdio.h>
>=20
> int
> foo (int a)
> {
> printf ("a =3D %d\n", a);
> return a;
> }
> EOF
> $cat > asm.as <<EOF
> global nothing
> ;export nothing
> nothing:
> ret
> end
> EOF
> $ cat > app.c <<EOF
> #include <stdio.h>
>=20
> extern int foo (int);
>=20
> int
> main ()
> {
> int x =3D foo (42);
> printf ("x =3D %d\n", x);
> nothing();
> return 0;
> }
> EOF
> $ gcc -g -c lib.c -o lib.o
> $ yasm -fx64 asm.as -o asm.o
> $ gcc -shared lib.o ams.o -Wl,--out-implib=3Dlib.dll.a -Wl,--export-all-
> symbols -o lib.dll
> $ gcc -g -o app app.c -L. -llib
> $ ./app
> ...
> <segfault>
>=20
> Without the export directive (commented above) I get __nm_ prefix and=20
> wrong callq instruction.
> With it, the __nm_prefix disappears and the trampoline correctly used.
I think you must define the export (gas: .def) pseudo op when creating
your own assembler code exporting a symbol from a DLL. If you look
into the code created by gcc from lib.c:
$ gcc -S lib.c
$ cat lib.s
.file "lib.c"
.section .rdata,"dr"
.LC0:
.ascii "a =3D %d\12\0"
.text
.globl foo
.def foo; .scl 2; .type 32; .endef
.seh_proc foo
foo:
pushq %rbp
.seh_pushreg %rbp
movq %rsp, %rbp
.seh_setframe %rbp, 0
subq $32, %rsp
.seh_stackalloc 32
.seh_endprologue
movl %ecx, 16(%rbp)
movl 16(%rbp), %edx
leaq .LC0(%rip), %rcx
call printf
movl 16(%rbp), %eax
addq $32, %rsp
popq %rbp
ret
.seh_endproc
.ident "GCC: (GNU) 4.8.2"
.def printf; .scl 2; .type 32; .endef
At this point gcc doesn't know that foo will get exported from a DLL,
but it generates the .def directive nevertheless. If I create the
same code in gas:
.text
.globl nothing
.def nothing; .scl 2; .type 32; .endef
nothing:
ret
then it works, but crashes if I omit the .def directive. So it seems
to me you don't have to export the symbol using the dllimport/dllexport
directives, but you have to specify the symbol explicitely for export.
Corinna
--vbzKE9fGfpHIBC6T
Content-Type: application/pgp-signature
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
iQIcBAEBAgAGBQJTQrfiAAoJEPU2Bp2uRE+gF3oP/0gLEzYz0JkWB4KhzNDF+d/k
2lBl//Hx/WX66l5fAomb//F0S8i9TqRO44qvWSWvsRNMr8Rgvs2OMh/89boNbqjR
7rbwJGPXI+uAVkNHPwjn8CwLdNObbN56ttKcs7lig0ZGabBOqxWUHCPj33NvJyi7
cQ4mgCmdF+A5LD+Aod0vtz0lLgR2KZcgA8fwyQSBCbzGIeoAIpOm/Np3EPRfEs2Y
S7G8N7jqdon2HMUbiL/QTFVz23Z1ckwbvw9r7g0Iktf6zRKkwzlsWuO+ZXPheWuS
AgdEgBJG+kTqNn3WQ1HD8sZ1+ntletrrTxprCox93rZOKx96lFUZr2rNsQ7S2esj
lweyshBOwAJCqOZeex1tDSgQovOTy6AFcTZupiLu2A+5gUhyyzJNKJ4PQ+Iy4Hm/
ihE+7ykuKccOWPT4FCtAvstkhYmwqlBZh4+3w22LMtl+6yNL6J6E7DN4TGXwuXho
o1rQ8ZmPbhshGL1BM7y4pKlkTVSqXjSMiJBp+4RMS/id1fPc6/036XrT2urdZ11a
PxytCUCfWtQmIgv6dED0CoIBwpkLGoSzqZ7vDsOwF7XIL4yPAAqKLR7dtYVRr4Wa
12k+/N6vp9iC7vYi6l98jANbwGyWJs9a9bS2T3FuQKL65V+Cg4w+lu9t8A0DZAE3
pRA3daaIFlzYBuHgXEyn
=hvBV
-----END PGP SIGNATURE-----
--vbzKE9fGfpHIBC6T--
- Raw text -