linux-kernelcross-compilingldflags

What is the signification of LDFLAGS


I'm trying to compile AODV for ARM linux. I use a SabreLite as a board with kernel version 3.0.35_4.1.0. It's worth mention that i'm using openembedded to create my Linux Distribution for my board. The AODV source code (http://sourceforge.net/projects/aodvuu/) has a README file which give some indications on how to install it on ARM as stated a bit here. (http://w3.antd.nist.gov/wctg/aodv_kernel/kaodv_arm.html).

I was able to upgrade the makefile in order to be used with post 2.6 kernel version ( as stated above, i have the 3.0.35_4.1.0 kernel version). So, basically, what i am trying to do is that i have to create a module (let's say file.ko) and then load it into the ARM (with insmod file.ko command).

To do that, i am using a cross compiler which some values are stated below:

when i launch "make command", i get the following errors:

LD [M] /home/scof/script_emulation/AODV/aodv-uu/lnx/kaodv.o

arm-oe-linux-gnueabi-ld: unrecognized option '-Wl,-O1'

arm-oe-linux-gnueabi-ld: use the --help option for usage information

It states that there is something wrong with the linker. This linker comes from the cross compilation tools and i normally shouldn't touch it.

Anyway, to get this above errors fixed, i try to withdraw the LDFLAGS like this: export LDFLAGS='', and after this, the make command works and i get the module kaodv.ko. But when i insert it into my ARM to check, it does not work. It actually freeze my terminal

So my question is, do i have to specify the LDFLAGS when compiling ? Does withdrawing LDFLAGS can have impact on the generated kernel module. Actually, i try to understand where might be the problem and the only thing that come to me is that may be i should not change manually the LDFLAGS. But if i don't change de LDFLAGS, i get the unrecognized option error.

My second question related to that is, what are the possibly value of LDFLAGS in ARM compilation

Thanks !!


Solution

  • echo $LDFLAGS : -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -Wl,--as-needed

    There are two common methods of invoking the linker in a GCC-based toolchain. One is to do it directly, but another is to use GCC as a front end to invoke the linker, rather than invoke it directly. When doing this, options intended for the linker are prefixed with -Wl, so that GCC knows to pass them through rather than interpret them itself.

    In your case the error message from LD itself

    arm-oe-linux-gnueabi-ld: unrecognized option '-Wl,-O1'

    Indicates that your build system is passing LDFLAGS directly to the linker, and not by way of GCC.

    Therefore, you should remove the -Wl, prefix and your LDFLAGS would instead be

    -O1 --hash-style=gnu --as-needed --as-needed

    (the duplication of the last argument is probably pointless but benign)