This is the mail archive of the mailing list for the glibc project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Problem with main() defined in shared object

I am having a problem when I try to run a set of programs that place main()
is a shared object.

I am building glibc 2.3.2 for an ARM target.

Consider the following:

#include <stdio.h>

int main() {
        printf("Got inside main\n");
        return 0;

int xx(int i){
        return 4+i;


xx: shared xx.o
        $(CC) -o xx xx.o

shared: main.o
        $(CC) -shared -o main.o

When I build xx, I do get an undefined reference to main (ultimately
from glibc/csu/arm/elf/start.S), as I believe I should, but when I
run the program, I get a segfault because __libc_start_main() calls
the passed-in main, which is 0.

When I run with LD_DEBUG=all, I don't see any mention of resolving the
"main" symbol, so it appears that start.S's reference of it is left as
0, which is passed into __libc_start_main().

If I define main in the base object instead of the shared object, then
all is well.

Where is the next place I should be looking, or is there a known fix for
this problem?  (It is entirely possible that I have something built
incorrectly, but most other things seem to be working just fine..)

Thanks for any help!

Marcus Hall

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]