+2018-07-31 Olivier Hainque <hainque@adacore.com>
+
+ * common.opt (nolibc): New option.
+ * doc/invoke.texi (Link Options): Document it.
+ * gcc.c (LINK_GCC_C_SEQUENCE_SPEC): Honor nolibc.
+ * config/alpha/linux.h: Likewise.
+ * config/arc/elf.h: Likewise.
+ * config/arm/uclinux-elf.h: Likewise.
+ * config/arm/unknown-elf.h: Likewise.
+ * config/avr/avrlibc.h: Likewise.
+ * config/bfin/bfin.h: Likewise.
+ * config/bfin/linux.h: Likewise.
+ * config/bfin/uclinux.h: Likewise.
+ * config/darwin.h: Likewise.
+ * config/darwin10.h: Likewise.
+ * config/darwin12.h: Likewise.
+ * config/gnu-user.h: Likewise.
+ * config/lm32/uclinux-elf.h: Likewise.
+ * config/pa/pa-hpux11.h: Likewise.
+ * config/pa/pa64-hpux.h: Likewise.
+ * config/sparc/sparc.h: Likewise.
+
2018-07-31 Olivier Hainque <hainque@adacore.com>
* gcc.c (getenv_spec_function): Prepend '/' to value for allowed
nostartfiles
Driver
+nolibc
+Driver
+
nostdlib
Driver
%{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s"
#define LINK_GCC_C_SEQUENCE_SPEC \
- "%{static|static-pie:--start-group} %G %L \
+ "%{static|static-pie:--start-group} %G %{!nolibc:%L} \
%{static|static-pie:--end-group}%{!static:%{!static-pie:%G}}"
/* Use --as-needed -lgcc_s for eh support. */
/* If no specs file is enforced, default to nosys libarary. */
#undef LINK_GCC_C_SEQUENCE_SPEC
#define LINK_GCC_C_SEQUENCE_SPEC \
- "--start-group %G %{!specs=*:-lc -lnosys} --end-group"
+ "--start-group %G %{!specs=*:%{!nolibc:-lc -lnosys}} --end-group"
#undef LINK_GCC_C_SEQUENCE_SPEC
#define LINK_GCC_C_SEQUENCE_SPEC \
- "%{static|static-pie:--start-group} %G %L \
- %{static|static-pie:--end-group}%{!static:%{!static-pie:%G %L}}"
+ "%{static|static-pie:--start-group} %G %{!nolibc:%L} \
+ %{static|static-pie:--end-group}%{!static:%{!static-pie:%G %{!nolibc:%L}}}"
/* Use --as-needed -lgcc_s for eh support. */
#ifdef HAVE_LD_AS_NEEDED
udivmoddi4, which will depend on the exception unwind routines,
which will depend on abort, which is defined in libc. */
#undef LINK_GCC_C_SEQUENCE_SPEC
-#define LINK_GCC_C_SEQUENCE_SPEC "--start-group %G %L --end-group"
+#define LINK_GCC_C_SEQUENCE_SPEC "--start-group %G %{!nolibc:%L} --end-group"
#undef LINK_GCC_C_SEQUENCE_SPEC
#define LINK_GCC_C_SEQUENCE_SPEC \
- "--start-group %G %L --end-group"
+ "--start-group %G %{!nolibc:%L} --end-group"
#endif
#define LINK_GCC_C_SEQUENCE_SPEC "\
- %{mfast-fp:-lbffastfp} %G %L %{mfast-fp:-lbffastfp} %G \
+ %{mfast-fp:-lbffastfp} %G %{!nolibc:%L} %{mfast-fp:-lbffastfp} %G \
"
#undef ASM_SPEC
#undef LINK_GCC_C_SEQUENCE_SPEC
#define LINK_GCC_C_SEQUENCE_SPEC \
- "%{static|static-pie:--start-group} %{mfast-fp:-lbffastfp} %G %L \
+ "%{static|static-pie:--start-group} %{mfast-fp:-lbffastfp} %G %{!nolibc:%L} \
%{static|static-pie:--end-group} \
%{!static:%{!static-pie:%{mfast-fp:-lbffastfp} %G}}"
#undef LINK_GCC_C_SEQUENCE_SPEC
#define LINK_GCC_C_SEQUENCE_SPEC "\
- %{mfast-fp:-lbffastfp} %G %L %{mfast-fp:-lbffastfp} %G \
+ %{mfast-fp:-lbffastfp} %G %{!nolibc:%L} %{mfast-fp:-lbffastfp} %G \
"
#undef TARGET_SUPPORTS_SYNC_CALLS
/* We only want one instance of %G, since libSystem (Darwin's -lc) does not depend
on libgcc. */
#undef LINK_GCC_C_SEQUENCE_SPEC
-#define LINK_GCC_C_SEQUENCE_SPEC "%G %L"
+#define LINK_GCC_C_SEQUENCE_SPEC "%G %{!nolibc:%L}"
/* ld64 supports a sysroot, it just has a different name and there's no easy
way to check for it at config time. */
%{!static:%{!static-libgcc: \
%:version-compare(>= 10.6 mmacosx-version-min= -lSystem) } } \
%{fno-pic|fno-PIC|fno-pie|fno-PIE|fapple-kext|mkernel|static|mdynamic-no-pic: \
- %:version-compare(>= 10.7 mmacosx-version-min= -no_pie) } %G %L"
+ %:version-compare(>= 10.7 mmacosx-version-min= -no_pie) } %G %{!nolibc:%L}"
#undef DEF_MIN_OSX_VERSION
#define DEF_MIN_OSX_VERSION "10.6"
%{!static:%{!static-libgcc: \
%:version-compare(>= 10.6 mmacosx-version-min= -lSystem) } } \
%{fno-pic|fno-PIC|fno-pie|fno-PIE|fapple-kext|mkernel|static|mdynamic-no-pic: \
- %:version-compare(>= 10.7 mmacosx-version-min= -no_pie) } %G %L"
+ %:version-compare(>= 10.7 mmacosx-version-min= -no_pie) } %G %{!nolibc:%L}"
#undef DEF_MIN_OSX_VERSION
#define DEF_MIN_OSX_VERSION "10.8"
#undef LINK_GCC_C_SEQUENCE_SPEC
#define LINK_GCC_C_SEQUENCE_SPEC \
- "%{static|static-pie:--start-group} %G %L \
+ "%{static|static-pie:--start-group} %G %{!nolibc:%L} \
%{static|static-pie:--end-group}%{!static:%{!static-pie:%G}}"
/* Use --as-needed -lgcc_s for eh support. */
#define TARGET_OS_CPP_BUILTINS() GNU_USER_TARGET_OS_CPP_BUILTINS()
#define LINK_GCC_C_SEQUENCE_SPEC \
- "%{static|static-pie:--start-group} %G %L \
+ "%{static|static-pie:--start-group} %G %{!nolibc:%L} \
%{static|static-pie:--end-group}%{!static:%{!static-pie:%G}}"
#undef CC1_SPEC
/* The libgcc_stub.a library needs to come last. */
#undef LINK_GCC_C_SEQUENCE_SPEC
#define LINK_GCC_C_SEQUENCE_SPEC \
- "%G %L %G %{!nostdlib:%{!nodefaultlibs:%{!shared:-lgcc_stub}}}"
+ "%G %{!nolibc:%L} %G %{!nostdlib:%{!nodefaultlibs:%{!shared:-lgcc_stub}}}"
#undef STARTFILE_SPEC
#define STARTFILE_SPEC \
/* The libgcc_stub.a and milli.a libraries need to come last. */
#undef LINK_GCC_C_SEQUENCE_SPEC
#define LINK_GCC_C_SEQUENCE_SPEC "\
- %G %L %G %{!nostdlib:%{!nodefaultlibs:%{!shared:-lgcc_stub}\
+ %G %{!nolibc:%L} %G %{!nostdlib:%{!nodefaultlibs:%{!shared:-lgcc_stub}\
milli.a%s}}"
/* Under hpux11, the normal location of the `ld' and `as' programs is the
/* Because libgcc can generate references back to libc (via .umul etc.) we have
to list libc again after the second libgcc. */
-#define LINK_GCC_C_SEQUENCE_SPEC "%G %L %G %L"
+#define LINK_GCC_C_SEQUENCE_SPEC "%G %{!nolibc:%L} %G %{!nolibc:%L}"
\f
#define PTRDIFF_TYPE (TARGET_ARCH64 ? "long int" : "int")
@item Linker Options
@xref{Link Options,,Options for Linking}.
@gccoptlist{@var{object-file-name} -fuse-ld=@var{linker} -l@var{library} @gol
--nostartfiles -nodefaultlibs -nostdlib -pie -pthread -rdynamic @gol
+-nostartfiles -nodefaultlibs -nolibc -nostdlib @gol
+-pie -pthread -rdynamic @gol
-s -static -static-pie -static-libgcc -static-libstdc++ @gol
-static-libasan -static-libtsan -static-liblsan -static-libubsan @gol
-shared -shared-libgcc -symbolic @gol
@item -nostartfiles
@opindex nostartfiles
Do not use the standard system startup files when linking.
-The standard system libraries are used normally, unless @option{-nostdlib}
-or @option{-nodefaultlibs} is used.
+The standard system libraries are used normally, unless @option{-nostdlib},
+@option{-nolibc}, or @option{-nodefaultlibs} is used.
@item -nodefaultlibs
@opindex nodefaultlibs
libc. These entry points should be supplied through some other
mechanism when this option is specified.
+@item -nolibc
+@opindex nolibc
+Do not use the C library or system libraries tightly coupled with it when
+linking. Still link with the startup files, @file{libgcc} or toolchain
+provided language support libraries such as @file{libgnat}, @file{libgfortran}
+or @file{libstdc++} unless options preventing their inclusion are used as
+well. This typically removes @option{-lc} from the link command line, as well
+as system libraries that normally go with it and become meaningless when
+absence of a C library is assumed, for example @option{-lpthread} or
+@option{-lm} in some configurations. This is intended for bare-board
+targets when there is indeed no C library available.
+
@item -nostdlib
@opindex nostdlib
Do not use the standard system startup files or libraries when linking.
-lgcc and -lc order specially, yet not require them to override all
of LINK_COMMAND_SPEC. */
#ifndef LINK_GCC_C_SEQUENCE_SPEC
-#define LINK_GCC_C_SEQUENCE_SPEC "%G %L %G"
+#define LINK_GCC_C_SEQUENCE_SPEC "%G %{!nolibc:%L %G}"
#endif
#ifndef LINK_SSP_SPEC