lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It was thus said that the Great Philippe Verdy once stated:
> Le dim. 25 nov. 2018 à 05:24, Sean Conner <sean@conman.org> a écrit :
> 
> >   Here's the same, but under Linux:
> >
> >         % cc    -c -o main.o main.c
> >         % cc    -c -o myfunc2.o myfunc2.c
> >         % cc -shared -fPIC -o func1.ss func1.c
> >         % cc -shared -fPIC -o func2.ss func2.c
> >         % cc -shared -o libfunc.so func1.ss func2.ss
> >         % cc  -Wl,-rpath,/tmp/foo -o smain4 main.o myfunc2.o libfunc.so
> >         % ./smain4
> >         Hello from main
> >                 Hello from func1
> >                         Hello from myfunc2 ********
> >                 Back to func1
> >         Back to main
> >                         Hello from myfunc2
> >         Back to main
> >
> > Again, look closely at the line marked with '********'.  Notice the
> > function
> > that was called---myfunc2().  NOT func2().  myfunc2().
> 
> You've used the PIC option which means that the shared library does not
> call directly the functions, but passes through a "call gate" to perform
> the indirection.

	% cc -c -o main.o main.c
	% cc -c -o myfunc2.o myfunc2.c
	% cc -shared -o func1.ss func1.c    *** < NOTE LACK OF -fPIC
	% cc -shared -o func2.ss func2.c    *** < NOTE LACK OF -fPIC
	% cc -shared -o libfunc.so func1.ss func2.ss
	% cc -Wl,-rpath,/tmp/foo -o smain4 main.o myfunc2.o libfunc.so 
	% ./smain4
	Hello from main
	        Hello from func1
	                Hello from myfunc2 *** < NOTE myfunc2 called!
	        Back to func1
	Back to main
	                Hello from myfunc2
	Back to main

And to further head off that I used "-shared" when compiling func1.c and
func2.c:

	% cc -c -o main.o main.c
	% cc -c -o myfunc2.o myfunc2.c
	% cc -c -o func1.ss func1.c    *** < NOTE LACK OF -shared -fPIC
	% cc -c -o func2.ss func2.c    *** < NOTE LACK OF -shared -fPIC
	% cc -shared -o libfunc.so func1.ss func2.ss
	% cc -Wl,-rpath,/tmp/foo -o smain4 main.o myfunc2.o libfunc.so 
	% ./smain4 
	Hello from main
	        Hello from func1
	                Hello from myfunc2   *** < NOTE myfunc2 called!
	        Back to func1
	Back to main
	                Hello from myfunc2
	Back to main
	% ldd ./smain4
	        libfunc.so => /tmp/foo/libfunc.so (0x00a9c000) *** < NOTE this is loading it at runtime!
	        libc.so.6 => /lib/tls/libc.so.6 (0x00b90000)
	        /lib/ld-linux.so.2 (0x00b76000)

And to head off that this is Linux specific, I'll do this for Solaris as
well:

	% cc -c -o main.o main.c
	% cc -c -o myfunc2.o myfunc2.c
	% cc -c -o func1.ss func1.c    *** < NOTE LACK OF -shared -xcode=pic32
	% cc -c -o func2.ss func2.c    *** < NOTE LACK OF -shared -xcode=pic32
	% cc -shared -o libfunc.so func1.ss func2.ss
	% cc -Wl,-R/lusr/home/spc/foo -o smain4 main.o myfunc2.o -L/lusr/home/spc/foo -lfunc
	% ldd smain4
        libfunc.so =>    ./libfunc.so
        libc.so.1 =>     /usr/lib/libc.so.1
        libm.so.2 =>     /usr/lib/libm.so.2
        /platform/SUNW,Sun-Fire-T1000/lib/libc_psr.so.1
	% ./smain4
	Hello from main
	        Hello from func1
	                Hello from myfunc2   *** < NOTE myfunc2 called!
	        Back to func1
	Back to main
	                Hello from myfunc2
	Back to main

  [ rest of possibly wrong post snipped ]

  -spc (I guess you coudn't bother to at least try it before writing ... )