From: Olivier Hainque Date: Tue, 31 Jul 2018 09:24:41 +0000 (+0000) Subject: Add support for -nolibc X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f37866e818ab839e0db68be23e5a339e5e7c19dc;p=gcc.git Add support for -nolibc 2018-06-07 Olivier Hainque * 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. From-SVN: r263083 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e2eb1c69fd0..cb0fb088548 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,25 @@ +2018-07-31 Olivier Hainque + + * 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 * gcc.c (getenv_spec_function): Prepend '/' to value for allowed diff --git a/gcc/common.opt b/gcc/common.opt index 4bf8de90331..5bb645291cf 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -3040,6 +3040,9 @@ Driver nostartfiles Driver +nolibc +Driver + nostdlib Driver diff --git a/gcc/config/alpha/linux.h b/gcc/config/alpha/linux.h index 2bf52fe78ae..6d12d90351b 100644 --- a/gcc/config/alpha/linux.h +++ b/gcc/config/alpha/linux.h @@ -105,7 +105,7 @@ along with GCC; see the file COPYING3. If not see %{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. */ diff --git a/gcc/config/arc/elf.h b/gcc/config/arc/elf.h index 66ee5b698ea..3472fd2e418 100644 --- a/gcc/config/arc/elf.h +++ b/gcc/config/arc/elf.h @@ -77,4 +77,4 @@ along with GCC; see the file COPYING3. If not see /* 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" diff --git a/gcc/config/arm/uclinux-elf.h b/gcc/config/arm/uclinux-elf.h index f78f279f0ab..57339832133 100644 --- a/gcc/config/arm/uclinux-elf.h +++ b/gcc/config/arm/uclinux-elf.h @@ -67,8 +67,8 @@ #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 diff --git a/gcc/config/arm/unknown-elf.h b/gcc/config/arm/unknown-elf.h index 12dd0931b08..6eeb0eb2d1f 100644 --- a/gcc/config/arm/unknown-elf.h +++ b/gcc/config/arm/unknown-elf.h @@ -93,4 +93,4 @@ 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" diff --git a/gcc/config/avr/avrlibc.h b/gcc/config/avr/avrlibc.h index 95a1d7c302f..f4a41a1b556 100644 --- a/gcc/config/avr/avrlibc.h +++ b/gcc/config/avr/avrlibc.h @@ -37,4 +37,4 @@ along with GCC; see the file COPYING3. If not see #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" diff --git a/gcc/config/bfin/bfin.h b/gcc/config/bfin/bfin.h index 4709282aab5..a503d579f1a 100644 --- a/gcc/config/bfin/bfin.h +++ b/gcc/config/bfin/bfin.h @@ -204,7 +204,7 @@ #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 diff --git a/gcc/config/bfin/linux.h b/gcc/config/bfin/linux.h index 9d317d10f24..b1592ee7754 100644 --- a/gcc/config/bfin/linux.h +++ b/gcc/config/bfin/linux.h @@ -35,7 +35,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #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}}" diff --git a/gcc/config/bfin/uclinux.h b/gcc/config/bfin/uclinux.h index 7ef3b16f984..beb6d457061 100644 --- a/gcc/config/bfin/uclinux.h +++ b/gcc/config/bfin/uclinux.h @@ -29,7 +29,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #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 diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h index 591188a1d19..980ad9b4057 100644 --- a/gcc/config/darwin.h +++ b/gcc/config/darwin.h @@ -210,7 +210,7 @@ extern GTY(()) int darwin_ms_struct; /* 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. */ diff --git a/gcc/config/darwin10.h b/gcc/config/darwin10.h index 7da32917742..d61eb40b8ff 100644 --- a/gcc/config/darwin10.h +++ b/gcc/config/darwin10.h @@ -28,7 +28,7 @@ along with GCC; see the file COPYING3. If not see %{!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" diff --git a/gcc/config/darwin12.h b/gcc/config/darwin12.h index f1562c5ad6c..e1e1eb085a2 100644 --- a/gcc/config/darwin12.h +++ b/gcc/config/darwin12.h @@ -24,7 +24,7 @@ along with GCC; see the file COPYING3. If not see %{!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" diff --git a/gcc/config/gnu-user.h b/gcc/config/gnu-user.h index b326cf069c5..5b48fb21514 100644 --- a/gcc/config/gnu-user.h +++ b/gcc/config/gnu-user.h @@ -135,7 +135,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #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. */ diff --git a/gcc/config/lm32/uclinux-elf.h b/gcc/config/lm32/uclinux-elf.h index cfaca372462..ac51d97050a 100644 --- a/gcc/config/lm32/uclinux-elf.h +++ b/gcc/config/lm32/uclinux-elf.h @@ -68,7 +68,7 @@ #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 diff --git a/gcc/config/pa/pa-hpux11.h b/gcc/config/pa/pa-hpux11.h index 8adfe18b190..0e960c3c15a 100644 --- a/gcc/config/pa/pa-hpux11.h +++ b/gcc/config/pa/pa-hpux11.h @@ -157,7 +157,7 @@ along with GCC; see the file COPYING3. If not see /* 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 \ diff --git a/gcc/config/pa/pa64-hpux.h b/gcc/config/pa/pa64-hpux.h index 6f70767c2a5..2c24238edb4 100644 --- a/gcc/config/pa/pa64-hpux.h +++ b/gcc/config/pa/pa64-hpux.h @@ -106,7 +106,7 @@ along with GCC; see the file COPYING3. If not see /* 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 diff --git a/gcc/config/sparc/sparc.h b/gcc/config/sparc/sparc.h index 032a91d467a..87358c7e90e 100644 --- a/gcc/config/sparc/sparc.h +++ b/gcc/config/sparc/sparc.h @@ -420,7 +420,7 @@ extern enum cmodel sparc_cmodel; /* 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}" #define PTRDIFF_TYPE (TARGET_ARCH64 ? "long int" : "int") diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 1dcdfb51c47..27097d77606 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -517,7 +517,8 @@ Objective-C and Objective-C++ Dialects}. @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 @@ -12350,8 +12351,8 @@ link an Objective-C or Objective-C++ program. @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 @@ -12368,6 +12369,18 @@ These entries are usually resolved by entries in 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. diff --git a/gcc/gcc.c b/gcc/gcc.c index 48689ed398a..da91112be5e 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -872,7 +872,7 @@ proper position among the other output files. */ -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