Difference between the linker flags

Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I'm adding c++ runtime and exception support to the Linux kernel. For that, I need to provide my own lib/gcc and lib/libstdc++instead of the standard libraries provided by the compiler.
So, I am confused with the flags that are to be passed to the linker. In a normal kernel's top-level Makefile, LD = $(CROSS_COMPILE)ld which enables the kernel to use the default standard libraries and startup files. For my kernel I'm using LD = $(CROSS_COMPILE)ld -nostdlib -nodefaultlibs -nostartfiles as said in a documentation. What I understood from gcc documentation is that passing -nostdlib to the linker is that of passing both -nodefaultlibs -nostartfiles. What's actually the difference between these flags?
linux linux-kernel gcc linker g++
add a comment |Â
up vote
1
down vote
favorite
I'm adding c++ runtime and exception support to the Linux kernel. For that, I need to provide my own lib/gcc and lib/libstdc++instead of the standard libraries provided by the compiler.
So, I am confused with the flags that are to be passed to the linker. In a normal kernel's top-level Makefile, LD = $(CROSS_COMPILE)ld which enables the kernel to use the default standard libraries and startup files. For my kernel I'm using LD = $(CROSS_COMPILE)ld -nostdlib -nodefaultlibs -nostartfiles as said in a documentation. What I understood from gcc documentation is that passing -nostdlib to the linker is that of passing both -nodefaultlibs -nostartfiles. What's actually the difference between these flags?
linux linux-kernel gcc linker g++
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm adding c++ runtime and exception support to the Linux kernel. For that, I need to provide my own lib/gcc and lib/libstdc++instead of the standard libraries provided by the compiler.
So, I am confused with the flags that are to be passed to the linker. In a normal kernel's top-level Makefile, LD = $(CROSS_COMPILE)ld which enables the kernel to use the default standard libraries and startup files. For my kernel I'm using LD = $(CROSS_COMPILE)ld -nostdlib -nodefaultlibs -nostartfiles as said in a documentation. What I understood from gcc documentation is that passing -nostdlib to the linker is that of passing both -nodefaultlibs -nostartfiles. What's actually the difference between these flags?
linux linux-kernel gcc linker g++
I'm adding c++ runtime and exception support to the Linux kernel. For that, I need to provide my own lib/gcc and lib/libstdc++instead of the standard libraries provided by the compiler.
So, I am confused with the flags that are to be passed to the linker. In a normal kernel's top-level Makefile, LD = $(CROSS_COMPILE)ld which enables the kernel to use the default standard libraries and startup files. For my kernel I'm using LD = $(CROSS_COMPILE)ld -nostdlib -nodefaultlibs -nostartfiles as said in a documentation. What I understood from gcc documentation is that passing -nostdlib to the linker is that of passing both -nodefaultlibs -nostartfiles. What's actually the difference between these flags?
linux linux-kernel gcc linker g++
edited Jun 27 at 10:48
SivaPrasath
3,88611737
3,88611737
asked Jun 27 at 10:15
jaya shankar reddy kommuru
84
84
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
These flags are defined in GCCâÂÂs spec files, so the best way to determine the differences between them is to look there:
gcc -dumpspecs
The relevant part is the link_command definition. This shows that -nostdlib, -nodefaultlibs and -nostartfiles have the following impact:
%!nostdlib:%!nodefaultlibs:%:pass-through-libs(%(link_gcc_c_sequence))â this addslibgcc,libpthread,libc,libieeeas necessary, using a macro and thelibandlibgccspec strings;%!nostdlib:%!nostartfiles:%Sâ this adds thestartfilespec string, , which specifies the object files to add to handle startup (crti.oetc.)%!nostdlib:%fvtable-verify=std: -lvtv -u_vtable_map_vars_start -u_vtable_map_vars_end %fvtable-verify=preinit: -lvtv -u_vtable_map_vars_start -u_vtable_map_vars_endâ this adds virtual table verification usinglibvtv%!nostdlib:%!nodefaultlibs:%mmpx:%fcheck-pointer-bounds: %static:--whole-archive -lmpx --no-whole-archive %:include(libmpx.spec)%(link_libmpx) %!static:%static-libmpx:-Bstatic --whole-archive %!static-libmpx:--push-state --no-as-needed -lmpx %!static-libmpx:--pop-state %static-libmpx:--no-whole-archive -Bdynamic %:include(libmpx.spec)%(link_libmpx)%mmpx:%fcheck-pointer-bounds:%!fno-chkp-use-wrappers: %static:-lmpxwrappers %!static:%static-libmpxwrappers:-Bstatic -lmpxwrappers %static-libmpxwrappers: -Bdynamicâ this handleslibmpx%!nostdlib:%!nodefaultlibs:%%:sanitize(address): %static-libasan:%:include(libsanitizer.spec)%(link_libasan) %static:%ecannot specify -static with -fsanitize=address %%:sanitize(thread): %static-libtsan:%:include(libsanitizer.spec)%(link_libtsan) %static:%ecannot specify -static with -fsanitize=thread %%:sanitize(undefined):%static-libubsan:-Bstatic -lubsan %static-libubsan:-Bdynamic %static-libubsan:%:include(libsanitizer.spec)%(link_libubsan) %%:sanitize(leak): %static-liblsan:%:include(libsanitizer.spec)%(link_liblsan)â this handles the various sanitisation options%!nostdlib:%!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)â this adds the stack protection options and repeats the C link sequence (whose libraries were already specified at the start)%!nostdlib:%!nostartfiles:%Eâ this adds theendfilespec string, which specifies the object files to add to handle left-overs (crtfastmath.o,crtend.oetc.)
As you understood from the documentation, -nostdlib is a superset of -nodefaultlibs and -nostartfiles. It also disables virtual table verification.
So -nostdlib is sufficient to disable all the related features; -nodefaultlibs and -nostartfiles donâÂÂt add anything to it. (But it doesnâÂÂt hurt to mention them too.)
OK I got it. But I cannot understand why there occurs a misalignment of load segments of vmlinux when the lineLD = $(CROSS_COMPILE)ld -nostdlibis changed toLD = $(CROSS_COMPILE)ld -nostdlib -nodefaultlibs -nostartfiles. Instead of aligning at a mutiple of 2MB, they align at 1KB or something like that.
â jaya shankar reddy kommuru
Jun 27 at 12:56
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
These flags are defined in GCCâÂÂs spec files, so the best way to determine the differences between them is to look there:
gcc -dumpspecs
The relevant part is the link_command definition. This shows that -nostdlib, -nodefaultlibs and -nostartfiles have the following impact:
%!nostdlib:%!nodefaultlibs:%:pass-through-libs(%(link_gcc_c_sequence))â this addslibgcc,libpthread,libc,libieeeas necessary, using a macro and thelibandlibgccspec strings;%!nostdlib:%!nostartfiles:%Sâ this adds thestartfilespec string, , which specifies the object files to add to handle startup (crti.oetc.)%!nostdlib:%fvtable-verify=std: -lvtv -u_vtable_map_vars_start -u_vtable_map_vars_end %fvtable-verify=preinit: -lvtv -u_vtable_map_vars_start -u_vtable_map_vars_endâ this adds virtual table verification usinglibvtv%!nostdlib:%!nodefaultlibs:%mmpx:%fcheck-pointer-bounds: %static:--whole-archive -lmpx --no-whole-archive %:include(libmpx.spec)%(link_libmpx) %!static:%static-libmpx:-Bstatic --whole-archive %!static-libmpx:--push-state --no-as-needed -lmpx %!static-libmpx:--pop-state %static-libmpx:--no-whole-archive -Bdynamic %:include(libmpx.spec)%(link_libmpx)%mmpx:%fcheck-pointer-bounds:%!fno-chkp-use-wrappers: %static:-lmpxwrappers %!static:%static-libmpxwrappers:-Bstatic -lmpxwrappers %static-libmpxwrappers: -Bdynamicâ this handleslibmpx%!nostdlib:%!nodefaultlibs:%%:sanitize(address): %static-libasan:%:include(libsanitizer.spec)%(link_libasan) %static:%ecannot specify -static with -fsanitize=address %%:sanitize(thread): %static-libtsan:%:include(libsanitizer.spec)%(link_libtsan) %static:%ecannot specify -static with -fsanitize=thread %%:sanitize(undefined):%static-libubsan:-Bstatic -lubsan %static-libubsan:-Bdynamic %static-libubsan:%:include(libsanitizer.spec)%(link_libubsan) %%:sanitize(leak): %static-liblsan:%:include(libsanitizer.spec)%(link_liblsan)â this handles the various sanitisation options%!nostdlib:%!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)â this adds the stack protection options and repeats the C link sequence (whose libraries were already specified at the start)%!nostdlib:%!nostartfiles:%Eâ this adds theendfilespec string, which specifies the object files to add to handle left-overs (crtfastmath.o,crtend.oetc.)
As you understood from the documentation, -nostdlib is a superset of -nodefaultlibs and -nostartfiles. It also disables virtual table verification.
So -nostdlib is sufficient to disable all the related features; -nodefaultlibs and -nostartfiles donâÂÂt add anything to it. (But it doesnâÂÂt hurt to mention them too.)
OK I got it. But I cannot understand why there occurs a misalignment of load segments of vmlinux when the lineLD = $(CROSS_COMPILE)ld -nostdlibis changed toLD = $(CROSS_COMPILE)ld -nostdlib -nodefaultlibs -nostartfiles. Instead of aligning at a mutiple of 2MB, they align at 1KB or something like that.
â jaya shankar reddy kommuru
Jun 27 at 12:56
add a comment |Â
up vote
0
down vote
accepted
These flags are defined in GCCâÂÂs spec files, so the best way to determine the differences between them is to look there:
gcc -dumpspecs
The relevant part is the link_command definition. This shows that -nostdlib, -nodefaultlibs and -nostartfiles have the following impact:
%!nostdlib:%!nodefaultlibs:%:pass-through-libs(%(link_gcc_c_sequence))â this addslibgcc,libpthread,libc,libieeeas necessary, using a macro and thelibandlibgccspec strings;%!nostdlib:%!nostartfiles:%Sâ this adds thestartfilespec string, , which specifies the object files to add to handle startup (crti.oetc.)%!nostdlib:%fvtable-verify=std: -lvtv -u_vtable_map_vars_start -u_vtable_map_vars_end %fvtable-verify=preinit: -lvtv -u_vtable_map_vars_start -u_vtable_map_vars_endâ this adds virtual table verification usinglibvtv%!nostdlib:%!nodefaultlibs:%mmpx:%fcheck-pointer-bounds: %static:--whole-archive -lmpx --no-whole-archive %:include(libmpx.spec)%(link_libmpx) %!static:%static-libmpx:-Bstatic --whole-archive %!static-libmpx:--push-state --no-as-needed -lmpx %!static-libmpx:--pop-state %static-libmpx:--no-whole-archive -Bdynamic %:include(libmpx.spec)%(link_libmpx)%mmpx:%fcheck-pointer-bounds:%!fno-chkp-use-wrappers: %static:-lmpxwrappers %!static:%static-libmpxwrappers:-Bstatic -lmpxwrappers %static-libmpxwrappers: -Bdynamicâ this handleslibmpx%!nostdlib:%!nodefaultlibs:%%:sanitize(address): %static-libasan:%:include(libsanitizer.spec)%(link_libasan) %static:%ecannot specify -static with -fsanitize=address %%:sanitize(thread): %static-libtsan:%:include(libsanitizer.spec)%(link_libtsan) %static:%ecannot specify -static with -fsanitize=thread %%:sanitize(undefined):%static-libubsan:-Bstatic -lubsan %static-libubsan:-Bdynamic %static-libubsan:%:include(libsanitizer.spec)%(link_libubsan) %%:sanitize(leak): %static-liblsan:%:include(libsanitizer.spec)%(link_liblsan)â this handles the various sanitisation options%!nostdlib:%!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)â this adds the stack protection options and repeats the C link sequence (whose libraries were already specified at the start)%!nostdlib:%!nostartfiles:%Eâ this adds theendfilespec string, which specifies the object files to add to handle left-overs (crtfastmath.o,crtend.oetc.)
As you understood from the documentation, -nostdlib is a superset of -nodefaultlibs and -nostartfiles. It also disables virtual table verification.
So -nostdlib is sufficient to disable all the related features; -nodefaultlibs and -nostartfiles donâÂÂt add anything to it. (But it doesnâÂÂt hurt to mention them too.)
OK I got it. But I cannot understand why there occurs a misalignment of load segments of vmlinux when the lineLD = $(CROSS_COMPILE)ld -nostdlibis changed toLD = $(CROSS_COMPILE)ld -nostdlib -nodefaultlibs -nostartfiles. Instead of aligning at a mutiple of 2MB, they align at 1KB or something like that.
â jaya shankar reddy kommuru
Jun 27 at 12:56
add a comment |Â
up vote
0
down vote
accepted
up vote
0
down vote
accepted
These flags are defined in GCCâÂÂs spec files, so the best way to determine the differences between them is to look there:
gcc -dumpspecs
The relevant part is the link_command definition. This shows that -nostdlib, -nodefaultlibs and -nostartfiles have the following impact:
%!nostdlib:%!nodefaultlibs:%:pass-through-libs(%(link_gcc_c_sequence))â this addslibgcc,libpthread,libc,libieeeas necessary, using a macro and thelibandlibgccspec strings;%!nostdlib:%!nostartfiles:%Sâ this adds thestartfilespec string, , which specifies the object files to add to handle startup (crti.oetc.)%!nostdlib:%fvtable-verify=std: -lvtv -u_vtable_map_vars_start -u_vtable_map_vars_end %fvtable-verify=preinit: -lvtv -u_vtable_map_vars_start -u_vtable_map_vars_endâ this adds virtual table verification usinglibvtv%!nostdlib:%!nodefaultlibs:%mmpx:%fcheck-pointer-bounds: %static:--whole-archive -lmpx --no-whole-archive %:include(libmpx.spec)%(link_libmpx) %!static:%static-libmpx:-Bstatic --whole-archive %!static-libmpx:--push-state --no-as-needed -lmpx %!static-libmpx:--pop-state %static-libmpx:--no-whole-archive -Bdynamic %:include(libmpx.spec)%(link_libmpx)%mmpx:%fcheck-pointer-bounds:%!fno-chkp-use-wrappers: %static:-lmpxwrappers %!static:%static-libmpxwrappers:-Bstatic -lmpxwrappers %static-libmpxwrappers: -Bdynamicâ this handleslibmpx%!nostdlib:%!nodefaultlibs:%%:sanitize(address): %static-libasan:%:include(libsanitizer.spec)%(link_libasan) %static:%ecannot specify -static with -fsanitize=address %%:sanitize(thread): %static-libtsan:%:include(libsanitizer.spec)%(link_libtsan) %static:%ecannot specify -static with -fsanitize=thread %%:sanitize(undefined):%static-libubsan:-Bstatic -lubsan %static-libubsan:-Bdynamic %static-libubsan:%:include(libsanitizer.spec)%(link_libubsan) %%:sanitize(leak): %static-liblsan:%:include(libsanitizer.spec)%(link_liblsan)â this handles the various sanitisation options%!nostdlib:%!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)â this adds the stack protection options and repeats the C link sequence (whose libraries were already specified at the start)%!nostdlib:%!nostartfiles:%Eâ this adds theendfilespec string, which specifies the object files to add to handle left-overs (crtfastmath.o,crtend.oetc.)
As you understood from the documentation, -nostdlib is a superset of -nodefaultlibs and -nostartfiles. It also disables virtual table verification.
So -nostdlib is sufficient to disable all the related features; -nodefaultlibs and -nostartfiles donâÂÂt add anything to it. (But it doesnâÂÂt hurt to mention them too.)
These flags are defined in GCCâÂÂs spec files, so the best way to determine the differences between them is to look there:
gcc -dumpspecs
The relevant part is the link_command definition. This shows that -nostdlib, -nodefaultlibs and -nostartfiles have the following impact:
%!nostdlib:%!nodefaultlibs:%:pass-through-libs(%(link_gcc_c_sequence))â this addslibgcc,libpthread,libc,libieeeas necessary, using a macro and thelibandlibgccspec strings;%!nostdlib:%!nostartfiles:%Sâ this adds thestartfilespec string, , which specifies the object files to add to handle startup (crti.oetc.)%!nostdlib:%fvtable-verify=std: -lvtv -u_vtable_map_vars_start -u_vtable_map_vars_end %fvtable-verify=preinit: -lvtv -u_vtable_map_vars_start -u_vtable_map_vars_endâ this adds virtual table verification usinglibvtv%!nostdlib:%!nodefaultlibs:%mmpx:%fcheck-pointer-bounds: %static:--whole-archive -lmpx --no-whole-archive %:include(libmpx.spec)%(link_libmpx) %!static:%static-libmpx:-Bstatic --whole-archive %!static-libmpx:--push-state --no-as-needed -lmpx %!static-libmpx:--pop-state %static-libmpx:--no-whole-archive -Bdynamic %:include(libmpx.spec)%(link_libmpx)%mmpx:%fcheck-pointer-bounds:%!fno-chkp-use-wrappers: %static:-lmpxwrappers %!static:%static-libmpxwrappers:-Bstatic -lmpxwrappers %static-libmpxwrappers: -Bdynamicâ this handleslibmpx%!nostdlib:%!nodefaultlibs:%%:sanitize(address): %static-libasan:%:include(libsanitizer.spec)%(link_libasan) %static:%ecannot specify -static with -fsanitize=address %%:sanitize(thread): %static-libtsan:%:include(libsanitizer.spec)%(link_libtsan) %static:%ecannot specify -static with -fsanitize=thread %%:sanitize(undefined):%static-libubsan:-Bstatic -lubsan %static-libubsan:-Bdynamic %static-libubsan:%:include(libsanitizer.spec)%(link_libubsan) %%:sanitize(leak): %static-liblsan:%:include(libsanitizer.spec)%(link_liblsan)â this handles the various sanitisation options%!nostdlib:%!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)â this adds the stack protection options and repeats the C link sequence (whose libraries were already specified at the start)%!nostdlib:%!nostartfiles:%Eâ this adds theendfilespec string, which specifies the object files to add to handle left-overs (crtfastmath.o,crtend.oetc.)
As you understood from the documentation, -nostdlib is a superset of -nodefaultlibs and -nostartfiles. It also disables virtual table verification.
So -nostdlib is sufficient to disable all the related features; -nodefaultlibs and -nostartfiles donâÂÂt add anything to it. (But it doesnâÂÂt hurt to mention them too.)
answered Jun 27 at 11:31
Stephen Kitt
139k22299361
139k22299361
OK I got it. But I cannot understand why there occurs a misalignment of load segments of vmlinux when the lineLD = $(CROSS_COMPILE)ld -nostdlibis changed toLD = $(CROSS_COMPILE)ld -nostdlib -nodefaultlibs -nostartfiles. Instead of aligning at a mutiple of 2MB, they align at 1KB or something like that.
â jaya shankar reddy kommuru
Jun 27 at 12:56
add a comment |Â
OK I got it. But I cannot understand why there occurs a misalignment of load segments of vmlinux when the lineLD = $(CROSS_COMPILE)ld -nostdlibis changed toLD = $(CROSS_COMPILE)ld -nostdlib -nodefaultlibs -nostartfiles. Instead of aligning at a mutiple of 2MB, they align at 1KB or something like that.
â jaya shankar reddy kommuru
Jun 27 at 12:56
OK I got it. But I cannot understand why there occurs a misalignment of load segments of vmlinux when the line
LD = $(CROSS_COMPILE)ld -nostdlib is changed to LD = $(CROSS_COMPILE)ld -nostdlib -nodefaultlibs -nostartfiles. Instead of aligning at a mutiple of 2MB, they align at 1KB or something like that.â jaya shankar reddy kommuru
Jun 27 at 12:56
OK I got it. But I cannot understand why there occurs a misalignment of load segments of vmlinux when the line
LD = $(CROSS_COMPILE)ld -nostdlib is changed to LD = $(CROSS_COMPILE)ld -nostdlib -nodefaultlibs -nostartfiles. Instead of aligning at a mutiple of 2MB, they align at 1KB or something like that.â jaya shankar reddy kommuru
Jun 27 at 12:56
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f452187%2fdifference-between-the-linker-flags%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password