dslm4515 / CMLFS

Clang-Built Musl Linux From Scratch
MIT License
105 stars 18 forks source link

Unable to build GCC with Clang (LLVM) #3

Closed dslm4515 closed 4 months ago

dslm4515 commented 3 years ago

While in chroot, building GCC to install in /opt/gnu with clang fails. GMP, MPC, MPFR, and Binutils are installed in /opt/gnu.

make[1]: Entering directory '/sources/gcc-10.2.1_pre2/build'
make[2]: Entering directory '/sources/gcc-10.2.1_pre2/build/libiberty'
rm -f ./libiberty.a pic/./libiberty.a noasan/./libiberty.a
/opt/gnu/bin/as rc ./libiberty.a \
  ./regex.o ./cplus-dem.o ./cp-demangle.o ./md5.o ./sha1.o ./alloca.o ./argv.o ./choose-temp.o ./concat.o ./cp-demint.o ./crc32.o ./d-demangle.o ./dwarfnames.o ./dyn-string.o ./fdmatch.o ./fibheap.o ./filedescriptor.o ./filename_cmp.o ./floatformat.o ./fnmatch.o ./fopen_unlocked.o ./getopt.o ./getopt1.o ./getpwd.o ./getruntime.o ./hashtab.o ./hex.o ./lbasename.o ./lrealpath.o ./make-relative-prefix.o ./make-temp-file.o ./objalloc.o ./obstack.o ./partition.o ./pexecute.o ./physmem.o ./pex-common.o ./pex-one.o ./pex-unix.o ./vprintf-support.o ./rust-demangle.o ./safe-ctype.o ./simple-object.o ./simple-object-coff.o ./simple-object-elf.o ./simple-object-mach-o.o ./simple-object-xcoff.o ./sort.o ./spaces.o ./splay-tree.o ./stack-limit.o ./strerror.o ./strsignal.o ./timeval-utils.o ./unlink-if-ordinary.o ./xasprintf.o ./xatexit.o ./xexit.o ./xmalloc.o ./xmemdup.o ./xstrdup.o ./xstrerror.o ./xstrndup.o ./xvasprintf.o  ./sigsetmask.o ./setproctitle.o
Assembler messages:
Error: can't open rc for reading: No such file or directory
rc: Error: can't open ./libiberty.a for reading: No such file or directory
./regex.o:1: Error: junk at end of line, first unrecognized character valued 0x7f

and ends with:

./setproctitle.o:4: Error: junk at end of line, first unrecognized character valued 0x8
./setproctitle.o:4: Error: junk at end of line, first unrecognized character valued 0x18
make[2]: *** [Makefile:252: libiberty.a] Error 1
make[2]: Leaving directory '/sources/gcc-10.2.1_pre2/build/libiberty'
make[1]: *** [Makefile:8362: all-libiberty] Error 2
make[1]: Leaving directory '/sources/gcc-10.2.1_pre2/build'
make: *** [Makefile:963: all] Error 2
dslm4515 commented 3 years ago

GCC is needed to build libelf from elfutils as clang has no real support for GNU99

dslm4515 commented 3 years ago

Use a fresh copy of cross-tools with /cross-tools/etc/ld-musl-$(uname -m).path modified to search /usr/lib and /lib of final system.

Using the gcc from cross-tools allows libelf to compile.

dslm4515 commented 9 months ago

Now with close to release of CMLFS 4.0.0 (LLVM 17.0.5 + elftoolchain), GCC 13.2.0 will not build GCC to install in /opt/gnu with gmp in /usr and mpc,mpfr, & binutils in /opt/gnu:

In file included from ../../gcc/cp/mapper-client.cc:31:                                   [195/1967]
In file included from ../../gcc/system.h:227:                                                       
In file included from /usr/bin/../include/c++/v1/map:2529:                              
In file included from /usr/bin/../include/c++/v1/functional:526:                                    
In file included from /usr/bin/../include/c++/v1/__functional/boyer_moore_searcher.h:27:            
In file included from /usr/bin/../include/c++/v1/vector:321:                                        
In file included from /usr/bin/../include/c++/v1/__format/formatter_bool.h:20:                      
In file included from /usr/bin/../include/c++/v1/__format/formatter_integral.h:32:                  
In file included from /usr/bin/../include/c++/v1/locale:202:                            
/usr/bin/../include/c++/v1/__locale:546:5: error: '__abi_tag__' attribute only applies to structs, v
ariables, functions, and namespaces                                                                 
  546 |     _LIBCPP_INLINE_VISIBILITY                                                               
      |     ^                                                                                       
/usr/bin/../include/c++/v1/__config:841:37: note: expanded from macro '_LIBCPP_INLINE_VISIBILITY'   
  841 | #  define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI                                   
      |                                     ^                                                       
/usr/bin/../include/c++/v1/__config:820:26: note: expanded from macro '_LIBCPP_HIDE_FROM_ABI'       
  820 |           __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_ODR_SIGNATURE))))             
      |                          ^                                                                  
In file included from ../../gcc/cp/mapper-client.cc:31:                                  
In file included from ../../gcc/system.h:227:
In file included from /usr/bin/../include/c++/v1/map:2529:
In file included from /usr/bin/../include/c++/v1/functional:526:
In file included from /usr/bin/../include/c++/v1/__functional/boyer_moore_searcher.h:27:
In file included from /usr/bin/../include/c++/v1/vector:321:
In file included from /usr/bin/../include/c++/v1/__format/formatter_bool.h:20:
In file included from /usr/bin/../include/c++/v1/__format/formatter_integral.h:32:
In file included from /usr/bin/../include/c++/v1/locale:202:
/usr/bin/../include/c++/v1/__locale:547:37: error: expected ';' at end of declaration list
  547 |     char_type toupper(char_type __c) const
      |                                     ^
/usr/bin/../include/c++/v1/__locale:553:48: error: too many arguments provided to function-like macr
o invocation
  553 |     const char_type* toupper(char_type* __low, const char_type* __high) const
      |                                                ^
../../gcc/../include/safe-ctype.h:146:9: note: macro 'toupper' defined here
  146 | #define toupper(c) do_not_use_toupper_with_safe_ctype
      |         ^
In file included from ../../gcc/cp/mapper-client.cc:31:
In file included from ../../gcc/system.h:227:
In file included from /usr/bin/../include/c++/v1/map:2529:
In file included from /usr/bin/../include/c++/v1/functional:526:
In file included from /usr/bin/../include/c++/v1/__functional/boyer_moore_searcher.h:27:
In file included from /usr/bin/../include/c++/v1/vector:321:
In file included from /usr/bin/../include/c++/v1/__format/formatter_bool.h:20:
In file included from /usr/bin/../include/c++/v1/__format/formatter_integral.h:32:
In file included from /usr/bin/../include/c++/v1/locale:202:
/usr/bin/../include/c++/v1/__locale:565:48: error: too many arguments provided to function-like macr
o invocation
  565 |     const char_type* tolower(char_type* __low, const char_type* __high) const
      |                                                ^
../../gcc/../include/safe-ctype.h:148:9: note: macro 'tolower' defined here
  148 | #define tolower(c) do_not_use_tolower_with_safe_ctype
      |         ^
In file included from ../../gcc/cp/mapper-client.cc:31:                                   [141/1967]
In file included from ../../gcc/system.h:227:
In file included from /usr/bin/../include/c++/v1/map:2529:
In file included from /usr/bin/../include/c++/v1/functional:526:
In file included from /usr/bin/../include/c++/v1/__functional/boyer_moore_searcher.h:27:
In file included from /usr/bin/../include/c++/v1/vector:321:
In file included from /usr/bin/../include/c++/v1/__format/formatter_bool.h:20:
In file included from /usr/bin/../include/c++/v1/__format/formatter_integral.h:32:
In file included from /usr/bin/../include/c++/v1/locale:202:
/usr/bin/../include/c++/v1/__locale:656:5: error: '__abi_tag__' attribute only applies to structs, v
ariables, functions, and namespaces
  656 |     _LIBCPP_INLINE_VISIBILITY
      |     ^
/usr/bin/../include/c++/v1/__config:841:37: note: expanded from macro '_LIBCPP_INLINE_VISIBILITY'
  841 | #  define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI
      |                                     ^
/usr/bin/../include/c++/v1/__config:820:26: note: expanded from macro '_LIBCPP_HIDE_FROM_ABI'
  820 |           __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_ODR_SIGNATURE))))
      |                          ^
In file included from ../../gcc/cp/mapper-client.cc:31:
In file included from ../../gcc/system.h:227:
In file included from /usr/bin/../include/c++/v1/map:2529:
In file included from /usr/bin/../include/c++/v1/functional:526:
In file included from /usr/bin/../include/c++/v1/__functional/boyer_moore_searcher.h:27:
In file included from /usr/bin/../include/c++/v1/vector:321:
In file included from /usr/bin/../include/c++/v1/__format/formatter_bool.h:20:
In file included from /usr/bin/../include/c++/v1/__format/formatter_integral.h:32:
In file included from /usr/bin/../include/c++/v1/locale:202:
/usr/bin/../include/c++/v1/__locale:657:37: error: expected ';' at end of declaration list
  657 |     char_type toupper(char_type __c) const 
      |                                     ^
/usr/bin/../include/c++/v1/__locale:663:48: error: too many arguments provided to function-like macr
o invocation
  663 |     const char_type* toupper(char_type* __low, const char_type* __high) const
      |                                                ^
../../gcc/../include/safe-ctype.h:146:9: note: macro 'toupper' defined here
  146 | #define toupper(c) do_not_use_toupper_with_safe_ctype
      |         ^
In file included from ../../gcc/cp/mapper-client.cc:31:
In file included from ../../gcc/system.h:227:
In file included from /usr/bin/../include/c++/v1/map:2529:
In file included from /usr/bin/../include/c++/v1/functional:526:
In file included from /usr/bin/../include/c++/v1/__functional/boyer_moore_searcher.h:27:
In file included from /usr/bin/../include/c++/v1/vector:321:
In file included from /usr/bin/../include/c++/v1/__format/formatter_bool.h:20:
In file included from /usr/bin/../include/c++/v1/__format/formatter_integral.h:32:
In file included from /usr/bin/../include/c++/v1/locale:202:
/usr/bin/../include/c++/v1/__locale:675:48: error: too many arguments provided to function-like macr
o invocation
  675 |     const char_type* tolower(char_type* __low, const char_type* __high) const
      |                                                ^
../../gcc/../include/safe-ctype.h:148:9: note: macro 'tolower' defined here
  148 | #define tolower(c) do_not_use_tolower_with_safe_ctype
      |         ^
In file included from ../../gcc/cp/mapper-client.cc:31:                                             
In file included from ../../gcc/system.h:227:                                                       
In file included from /usr/bin/../include/c++/v1/map:2529:                                          
In file included from /usr/bin/../include/c++/v1/functional:526:                                    
In file included from /usr/bin/../include/c++/v1/__functional/boyer_moore_searcher.h:27:            
In file included from /usr/bin/../include/c++/v1/vector:321:                                        
In file included from /usr/bin/../include/c++/v1/__format/formatter_bool.h:20:
In file included from /usr/bin/../include/c++/v1/__format/formatter_integral.h:32:
In file included from /usr/bin/../include/c++/v1/locale:202:                            
/usr/bin/../include/c++/v1/__locale:799:1: error: declaration conflicts with target of using declara
tion already in scope                                                                               
  799 | isprint(_CharT __c, const locale& __loc)                                                    
      | ^                                                                                           
/usr/include/ctype.h:17:7: note: target of using declaration                                        
   17 | int   isprint(int);                                                                        
      |       ^                                   
/usr/bin/../include/c++/v1/cctype:119:9: note: using declaration                                    
  119 | using ::isprint _LIBCPP_USING_IF_EXISTS;                                                    
      |         ^                                                                                   
In file included from ../../gcc/cp/mapper-client.cc:31:                                             
In file included from ../../gcc/system.h:227:                                                       
In file included from /usr/bin/../include/c++/v1/map:2529:                                          
In file included from /usr/bin/../include/c++/v1/functional:526:
In file included from /usr/bin/../include/c++/v1/__functional/boyer_moore_searcher.h:27:
In file included from /usr/bin/../include/c++/v1/vector:321:                            
In file included from /usr/bin/../include/c++/v1/__format/formatter_bool.h:20:
In file included from /usr/bin/../include/c++/v1/__format/formatter_integral.h:32:
In file included from /usr/bin/../include/c++/v1/locale:202:                      
/usr/bin/../include/c++/v1/__locale:801:5: error: expected expression
  801 |     return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c);                
      |     ^        
/usr/bin/../include/c++/v1/__locale:802:2: error: expected ';' at end of declaration                
  802 | }
      |  ^                                                                                          
/usr/bin/../include/c++/v1/__locale:807:21: error: too many arguments provided to function-like macr
o invocation             
  807 | iscntrl(_CharT __c, const locale& __loc)                                                    
      |                     ^                   
../../gcc/../include/safe-ctype.h:128:9: note: macro 'iscntrl' defined here                         
  128 | #define iscntrl(c) do_not_use_iscntrl_with_safe_ctype
      |         ^ 
In file included from ../../gcc/cp/mapper-client.cc:31:   
In file included from ../../gcc/system.h:227:                                                       
In file included from /usr/bin/../include/c++/v1/map:2529:                              
In file included from /usr/bin/../include/c++/v1/functional:526:
In file included from /usr/bin/../include/c++/v1/__functional/boyer_moore_searcher.h:27:
In file included from /usr/bin/../include/c++/v1/vector:321:                      
In file included from /usr/bin/../include/c++/v1/__format/formatter_bool.h:20:
In file included from /usr/bin/../include/c++/v1/__format/formatter_integral.h:32:
In file included from /usr/bin/../include/c++/v1/locale:202:                        
/usr/bin/../include/c++/v1/__locale:807:1: error: declaration conflicts with target of using declara
tion already in scope                                                                               
  807 | iscntrl(_CharT __c, const locale& __loc)                                                   
      | ^ 
/usr/include/ctype.h:13:7: note: target of using declaration                                        
   13 | int   iscntrl(int);                                                                        
      |       ^                                   
/usr/bin/../include/c++/v1/cctype:115:9: note: using declaration                                    
  115 | using ::iscntrl _LIBCPP_USING_IF_EXISTS;                                                    
      |         ^                                                                                   
In file included from ../../gcc/cp/mapper-client.cc:31:                                             
In file included from ../../gcc/system.h:227:
In file included from /usr/bin/../include/c++/v1/map:2529:
In file included from /usr/bin/../include/c++/v1/functional:526:
In file included from /usr/bin/../include/c++/v1/__functional/boyer_moore_searcher.h:27:
In file included from /usr/bin/../include/c++/v1/vector:321:
In file included from /usr/bin/../include/c++/v1/__format/formatter_bool.h:20:
In file included from /usr/bin/../include/c++/v1/__format/formatter_integral.h:32:
In file included from /usr/bin/../include/c++/v1/locale:202:
/usr/bin/../include/c++/v1/__locale:809:5: error: expected expression
  809 |     return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c);
      |     ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
1 warning and 20 errors generated.
make[2]: *** [Makefile:1157: cp/mapper-client.o] Error 1
make[2]: *** Waiting for unfinished jobs....
4 warnings generated.
6 warnings generated.
8 warnings generated.
rm gcc.pod
make[2]: Leaving directory '/sources/gcc-13.2.0/build/gcc'
make[1]: *** [Makefile:4623: all-gcc] Error 2
make[1]: Leaving directory '/sources/gcc-13.2.0/build'
make: *** [Makefile:1040: all] Error 2
dslm4515 commented 9 months ago

Perhaps this commit from freeBSD may provide insight?

This is because gcc/system.h includes safe-ctype.h which redefines ctype macros such as toupper, tolower, etc to "poison" them.

However, it should only include the safe-ctype.h header after any C++ headers, such as , , , etc, otherwise these might transitively include internal ctype headers (such as with libc++ 17), causing the above conflicts.

Fix it by moving the safe-ctype.h inclusion to later in gcc/system.h, which solves this issue, and makes it possible to build against libc++ 17.

Possible to use this patch from this bug report: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111632

dslm4515 commented 9 months ago

Tried the patch from above. New error:

In file included from ../../libcc1/libcc1plugin.cc:72:
In file included from /usr/include/c++/v1/vector:321:
In file included from /usr/include/c++/v1/__format/formatter_bool.h:20:
In file included from /usr/include/c++/v1/__format/formatter_integral.h:32:
/usr/include/c++/v1/locale:289:36: error: attempt to use a poisoned identifier
  289 |         __status = (unsigned char*)malloc(__nkw);
      |                                    ^
/usr/include/c++/v1/locale:1592:28: error: attempt to use a poisoned identifier
 1592 |         __ob = (char_type*)malloc(2*static_cast<size_t>(__nc)*sizeof(char_type));
      |                            ^
/usr/include/c++/v1/locale:2830:27: error: attempt to use a poisoned identifier
 2830 |     _Tp* __t = (_Tp*)std::realloc(__owns ? __b.get() : 0, __new_cap);
      |                           ^
/usr/include/c++/v1/locale:3074:30: error: attempt to use a poisoned identifier
 3074 |             __h.reset((char*)malloc(static_cast<size_t>(__wn - __wb.get() + 2)));
      |                              ^
/usr/include/c++/v1/locale:3372:32: error: attempt to use a poisoned identifier
 3372 |         __hd.reset((char_type*)malloc(static_cast<size_t>(__n) * sizeof(char_type)));
      |                                ^
/usr/include/c++/v1/locale:3400:32: error: attempt to use a poisoned identifier
 3400 |         __hw.reset((char_type*)malloc(__exn * sizeof(char_type)));
      |                                ^
/usr/include/c++/v1/locale:3442:31: error: attempt to use a poisoned identifier
 3442 |         __h.reset((char_type*)malloc(__exn * sizeof(char_type)));
      |                               ^
2 warnings and 7 errors generated.
make[3]: *** [Makefile:608: libcc1plugin.lo] Error 1
make[3]: Leaving directory '/sources/gcc-13.2.0/build/libcc1'
make[2]: *** [Makefile:443: all] Error 2
make[2]: Leaving directory '/sources/gcc-13.2.0/build/libcc1'
make[1]: *** [Makefile:11451: all-libcc1] Error 2
make[1]: Leaving directory '/sources/gcc-13.2.0/build'
make: *** [Makefile:1040: all] Error 2
dslm4515 commented 9 months ago

Same error if I applied patches from Alpine Linux

dslm4515 commented 9 months ago

Enabling bootstrapping allowed GCC to compile.

Likely a bootstrap xgcc had to be built first [via bootstrap process] in order to build GCC, instead of directly building GCC with clang.

Final GCC build was not built with the LDFLAGS specified with configure (-Wl,--rpath=/opt/gnu/lib), therefore, use patchelf to set the run-path for those binaries that require gmp, mpc, and/or mpfr

dslm4515 commented 9 months ago

GCC now builds after commit 60ddc94225e2d53832a4a369462e94a5603b2ecf

dslm4515 commented 5 months ago

Cross-compiling CMLFS for i686 on an amd64 host.

GCC fails to compile due to unable to fince libc:

ld: error: unable to find library -lc
collect2: error: ld returned 1 exit status
make[3]: *** [Makefile:998: libgcc_s.so] Error 1
make[3]: Leaving directory '/sources/gcc-13.2.0/build/i686-pc-linux-musl/libgcc'
dslm4515 commented 5 months ago

Add a link? ln -sv /usr/lib/libc.so /opt/gnu/lib/

No. Build continues but stops again:

 configure: error: Pthreads are required to build libgomp
make[2]: *** [Makefile:21800: configure-stage1-target-libgomp] Error 1
make[2]: Leaving directory '/sources/gcc-13.2.0/build'
make[1]: *** [Makefile:24158: stage1-bubble] Error 2
make[1]: Leaving directory '/sources/gcc-13.2.0/build'
make: *** [Makefile:1078: all] Error 2

Inspect the config.log:

ld: error: unable to find library -lpthread
dslm4515 commented 5 months ago

According to the above mentioned bug report, Build GCC with bootstrap disabled?

dslm4515 commented 5 months ago

No still stops at ld: error: unable to find library -lc

dslm4515 commented 5 months ago

Added more flags to configure (as seen in Alpine Linux):

LDFLAGS="-Wl,-rpath=/opt/gnu/lib -Wl,-rpath=/usr/lib -L/opt/gnu/lib -L/usr/lib " \
CFLAGS="-Wl,-rpath=/opt/gnu/lib -Wl,-rpath=/usr/lib -L/opt/gnu/lib -L/usr/lib " \
CXXFLAGS="-Wl,-rpath=/opt/gnu/lib -Wl,-rpath=/usr/lib -L/opt/gnu/lib -L/usr/lib " \
CFLAGS_FOR_TARGET=$CFLAGS CXXFLAGS_FOR_TARGET=$CXXFLAGS LDFLAGS_FOR_TARGET=$LDFLAGS \
BOOT_CFLAGS=$CFLAGS BOOT_CXXFLAGS=$CXXFLAGS BOOT_LDFLAGS=$LDFLAGS

Nope. GCC fails to build the lto-plugin:

ld: error: unable to find library -lssp_nonshared
ld: error: unable to find library -lc
configure:3641: error: in `/sources/gcc-13.2.0/build/lto-plugin':
configure:3643: error: C compiler cannot create executables

Applied an old patch from Alpine Linux:

patch -Np1 -i ../patches/gcc-alpine/0021-Alpine-musl-package-provides-libssp_nonshared.a.-We-.patch

Same error of ld: error: unable to find library -lssp_nonshared and ld: error: unable to find library -lc

dslm4515 commented 4 months ago

Issue fixed with commit b352c54ac7fd30b257ddf803e75735bfacb4e985

Use git snapshot of gcc-13.2.1 from Alpine Linux and use patches from Alpine Linux.