Compiling applications using cross compiler packs libc

4 messages, 4 authors, 2008-05-14 · open the first message on its own page

Compiling applications using cross compiler packs libc

From: Ramkumar J <hidden>
Date: 2008-05-12 09:12:46

Hi All,

I am trying to execute a compiled simple stand-alone application (
TestApp_Memory.c compiled with gcc 4.1.0 cross compiler for ppc [ I have
installed this through crosstool on a Linux PC ] ) on the ML403 Board
instead of using the compiler-set provided by XPS. I tried many options (
like --static to gcc) to make the object file little as produced by the XPS
Compiler Set. I find that when static is provided, the glibc is also packed
up as a part of application though I never make any calls to the glibc
libraries. If I dont provide the --static, the gcc produces a code assuming
the library as shared and hence I get an interp section.
Is there any way to produce the code  with only the application and NOT the
glibc ( As XPS compilers does). Am I missing out something. Is there any
specific flags. I find even nodefaultlib does not work.

For Eg: This is another example I tried

int main()
{
    int a = 5;
    int b = 10;
    int c = 15;

    c = a + b;

    c += 12;

    return 0;
}

With --static compilation, size is about 500K for the above code though the
useful content is too less. objdump reveals unneccessary calls to the libc.
Any suggestions would be helpful.

Thanks and Regards,
Ramkumar

Re: Compiling applications using cross compiler packs libc

From: Marco Stornelli <hidden>
Date: 2008-05-12 10:02:54

Ramkumar J ha scritto:
Hi All,

I am trying to execute a compiled simple stand-alone application (
TestApp_Memory.c compiled with gcc 4.1.0 cross compiler for ppc [ I have
installed this through crosstool on a Linux PC ] ) on the ML403 Board
instead of using the compiler-set provided by XPS. I tried many options (
like --static to gcc) to make the object file little as produced by the XPS
Compiler Set. I find that when static is provided, the glibc is also packed
up as a part of application though I never make any calls to the glibc
libraries. If I dont provide the --static, the gcc produces a code assuming
the library as shared and hence I get an interp section.
Is there any way to produce the code  with only the application and NOT the
glibc ( As XPS compilers does). Am I missing out something. Is there any
specific flags. I find even nodefaultlib does not work.

For Eg: This is another example I tried

int main()
{
    int a = 5;
    int b = 10;
    int c = 15;

    c = a + b;

    c += 12;

    return 0;
}

With --static compilation, size is about 500K for the above code though the
useful content is too less. objdump reveals unneccessary calls to the libc.
Any suggestions would be helpful.

Thanks and Regards,
Ramkumar



------------------------------------------------------------------------

5 more quoted lines

You shouldn't use --static but -Os to have a "little" program. With static you include all the libraries in your application therefore you have a bigger application. In addition libc are basic libraries so you have to use it. If you have size problems you can use uclibc.

Re: Compiling applications using cross compiler packs libc

From: Alessandro Rubini <hidden>
Date: 2008-05-12 10:33:36

the glibc is also packed
up as a part of application though I never make any calls to the glibc
libraries.
As already pointed out by Marco Stornelli, you shouldn't get concerned
about glibc as it's a standard library and you expect it to be part of
the target system (again, use uclibc if size is an issue).

If however you really want to build an application without library, you
should change the linker script. The kernel is not calling main() directly,
there is some initial setup involved, and this is where glibc (or uclibc)
is involved, even if you do no library calls yourself.

Look at a boot loader, or at the kernel, and then to proper
documentation, to find how to provide your own linker script to avoid
a library. But I doubt you really need it.

/alessandro

Re: Compiling applications using cross compiler packs libc

From: David H. Lynch Jr. <hidden>
Date: 2008-05-14 06:04:11

Alessandro Rubini wrote:
quoted
the glibc is also packed
up as a part of application though I never make any calls to the glibc
libraries.
    
If however you really want to build an application without library, you
should change the linker script. 
some or all of the following gcc flags might be useful if you are truly
compiling an OS independent very small application
-U__linux__
-nostdlib
-nostdinc
-mno-eabi
-fno-builtin
-nostartfiles
-nodefaultlibs
-nostdlib
Also as Alessandro pointed out you will likely need a link script.

-- 
Dave Lynch 					  	    DLA Systems
Software Development:  				         Embedded Linux
717.627.3770 	       dhlii@dlasys.net 	  http://www.dlasys.net
fax: 1.253.369.9244 			           Cell: 1.717.587.7774
Over 25 years' experience in platforms, languages, and technologies too numerous to list.

"Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction."
Albert Einstein
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help