Code:
# cat main.c
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
#include <errno.h>
typedef void (*FP)(void);
void printme (void) {
printf ("printed me hurray!!!\n");
}
int
main( int argc, char** argv )
{
void* handle;
void* symptr;
FP fp;
/*** Load the shared object containing the definition of the ***/
/*** function . defsym(). ***/
if ( NULL == ( handle = dlopen( "./libdefsym.so", RTLD_NOW ) ) ){
perror( dlerror() );
exit( 1 );
}
/**** Obtain the address of the function defsym. ***/
if ( NULL == ( symptr = dlsym( handle, "defsym" ) ) ) {
if ( 0 == errno ) {
fprintf( stderr, "Symbol defsym not found. Exiting\n"
);
exit( 1 );
}
perror( dlerror() );
exit( 1 );
}
fp = ( FP )symptr;
/*** Call the function via the obtained function address. ***/
fp();
/*** Unload the previously loaded shared object. ***/
if ( 0 != ( dlclose( handle ) ) ) {
perror( dlerror() );
exit( 1 );
}
exit( 0 );
}
defsym.c
#include <stdio.h>
#include <stdlib.h>
void
defsym()
{
printf( "defsym called.\n" );
printme();
}
cat toexp.exp
#!.
printme
Makefile
CC=gcc
CFLAGS= -g -maix64
all: main libdefsym.so
main: main.o
$(CC) -maix64 -o main main.o
main.o: main.c
$(CC) $(CFLAGS) -c main.c
libdefsym.so: defsym.o
ld -G -bnoentry -bexpall -bE:toexp.exp -o libdefsym.so defsym.o -lc
defsym.o: defsym.c
$(CC) $(CFLAGS) -c defsym.c
.PHONY: clean
clean:
rm *.o *.so main
# dbx ./main core
Type 'help' for help.
[using memory image in core]
reading symbolic information ...internal error: 1283-228 expected char ',', found ';-31,448,256;;'
internal error: 1283-228 expected char ';', found ',256;;'
internal error: 1283-232 index("256;;", ':') failed
internal error: unexpected value 120 at line 5176 in file stabstring.c
internal error: 1283-228 expected char ',', found 's__LC_locale:,1088,64;__meth_ptr:13,1152,64;__data_ptr:13,1216,64;;'
internal error: 1283-228 expected char ',', found '__LC_locale:,1088,64;__meth_ptr:13,1152,64;__data_ptr:13,1216,64;;'
internal error: 1283-228 expected char ';', found '_LC_locale:,1088,64;__meth_ptr:13,1152,64;__data_ptr:13,1216,64;;'
internal error: unexpected value 44 at line 5176 in file stabstring.c
internal error: 1283-228 expected char ',', found '1088,64;__meth_ptr:13,1152,64;__data_ptr:13,1216,64;;'
internal error: unexpected value 120 at line 5176 in file stabstring.c
internal error: unexpected value 120 at line 5176 in file stabstring.c
internal error: 1283-228 expected char ',', found 's_LC_locale_objhdl:,128,64;;'
internal error: 1283-228 expected char ',', found '_LC_locale_objhdl:,128,64;;'
internal error: 1283-228 expected char ';', found 'LC_locale_objhdl:,128,64;;'
internal error: unexpected value 44 at line 5176 in file stabstring.c
internal error: 1283-228 expected char ',', found '128,64;;'
internal error: unexpected value 120 at line 5176 in file stabstring.c
internal error: unexpected value 120 at line 5176 in file stabstring.c
internal error: unexpected value 120 at line 5176 in file stabstring.c
internal error: unexpected value 120 at line 5176 in file stabstring.c
internal error: unexpected value 120 at line 5176 in file stabstring.c
internal error: unexpected value 120 at line 5176 in file stabstring.c
internal error: unexpected value 120 at line 5176 in file stabstring.c
Illegal instruction (illegal opcode) in . at 0x0
warning: Unable to access address 0x0 from core
(dbx) where
.() at 0x0
internal error: 1283-228 expected char ',', found ';-31,448,256;;'
internal error: 1283-228 expected char ';', found ',256;;'
internal error: 1283-232 index("256;;", ':') failed
internal error: unexpected value 120 at line 5176 in file stabstring.c
internal error: 1283-228 expected char ',', found 's__LC_locale:,1088,64;__meth_ptr:13,1152,64;__data_ptr:13,1216,64;;'
internal error: 1283-228 expected char ',', found '__LC_locale:,1088,64;__meth_ptr:13,1152,64;__data_ptr:13,1216,64;;'
internal error: 1283-228 expected char ';', found '_LC_locale:,1088,64;__meth_ptr:13,1152,64;__data_ptr:13,1216,64;;'
internal error: unexpected value 44 at line 5176 in file stabstring.c
internal error: 1283-228 expected char ',', found '1088,64;__meth_ptr:13,1152,64;__data_ptr:13,1216,64;;'
internal error: unexpected value 120 at line 5176 in file stabstring.c
internal error: unexpected value 120 at line 5176 in file stabstring.c
internal error: 1283-228 expected char ',', found 's_LC_locale_objhdl:,128,64;;'
internal error: 1283-228 expected char ',', found '_LC_locale_objhdl:,128,64;;'
internal error: 1283-228 expected char ';', found 'LC_locale_objhdl:,128,64;;'
internal error: unexpected value 44 at line 5176 in file stabstring.c
internal error: 1283-228 expected char ',', found '128,64;;'
internal error: unexpected value 120 at line 5176 in file stabstring.c
internal error: unexpected value 120 at line 5176 in file stabstring.c
internal error: unexpected value 120 at line 5176 in file stabstring.c
internal error: unexpected value 120 at line 5176 in file stabstring.c
internal error: unexpected value 120 at line 5176 in file stabstring.c
internal error: unexpected value 120 at line 5176 in file stabstring.c
internal error: unexpected value 120 at line 5176 in file stabstring.c
defsym(), line 8 in "defsym.c"
main(argc = 1, argv = 0x0ffffffffffff9e0), line 36 in "main.c"
(dbx)