source: chapter06/gcc-pass2.xml@ 459d493

11.2 11.2-rc1 multilib s6-init trunk xry111/arm64 xry111/clfs-ng xry111/lfs-next xry111/pip3 xry111/queue-11.3 xry111/rust-wip-20221008
Last change on this file since 459d493 was 459d493, checked in by Xi Ruoyao <xry111@…>, 10 months ago

fix GCC PR100017 and enable libstdc++ for pass 2

This is the issue preventing us from cross-compiling libstdc++ in
Chapter 6. By fixing this issue we can remove a seperate pass 2 for
libstdc++ and simplify the instruction.

The upstream fix will be released in 11.3 and 12.0, so we can remove the
first sed upgrading gcc next time.

  • Property mode set to 100644
File size: 5.7 KB
Line 
1<?xml version="1.0" encoding="ISO-8859-1"?>
2<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
4 <!ENTITY % general-entities SYSTEM "../general.ent">
5 %general-entities;
6]>
7
8<sect1 id="ch-tools-gcc-pass2" role="wrap" xreflabel="gcc-pass2">
9 <?dbhtml filename="gcc-pass2.html"?>
10
11 <sect1info condition="script">
12 <productname>gcc-pass2</productname>
13 <productnumber>&gcc-version;</productnumber>
14 <address>&gcc-url;</address>
15 </sect1info>
16
17 <title>GCC-&gcc-version; - Pass 2</title>
18
19 <indexterm zone="ch-tools-gcc-pass2">
20 <primary sortas="a-GCC">GCC</primary>
21 <secondary>tools, pass 2</secondary>
22 </indexterm>
23
24 <sect2 role="package">
25 <title/>
26
27 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
28 href="../chapter08/gcc.xml"
29 xpointer="xpointer(/sect1/sect2[1]/para[1])"/>
30
31 <segmentedlist>
32 <segtitle>&buildtime;</segtitle>
33 <segtitle>&diskspace;</segtitle>
34
35 <seglistitem>
36 <seg>&gcc-tmpp2-sbu;</seg>
37 <seg>&gcc-tmpp2-du;</seg>
38 </seglistitem>
39 </segmentedlist>
40
41 </sect2>
42
43 <sect2 role="installation">
44 <title>Installation of GCC</title>
45
46 <para>As in the first build of GCC, the GMP, MPFR, and MPC packages are
47 required. Unpack the tarballs and move them into the required directory
48 names:</para>
49
50<screen><userinput remap="pre">tar -xf ../mpfr-&mpfr-version;.tar.xz
51mv -v mpfr-&mpfr-version; mpfr
52tar -xf ../gmp-&gmp-version;.tar.xz
53mv -v gmp-&gmp-version; gmp
54tar -xf ../mpc-&mpc-version;.tar.gz
55mv -v mpc-&mpc-version; mpc</userinput></screen>
56
57 <para>If building on x86_64, change the default directory name for 64-bit
58 libraries to <quote>lib</quote>:</para>
59
60<screen><userinput remap="pre">case $(uname -m) in
61 x86_64)
62 sed -e '/m64=/s/lib64/lib/' -i.orig gcc/config/i386/t-linux64
63 ;;
64esac</userinput></screen>
65
66 <!-- https://gcc.gnu.org/PR100017 -->
67 <para>Fix an issue causing failure cross-compiling libstdc++:</para>
68
69<screen><userinput remap="pre">sed 's/gnu++17/&amp; -nostdinc++/' \
70 -i libstdc++-v3/src/c++17/Makefile.in</userinput></screen>
71
72 <para>Override the building rule of libgcc and libstdc++ headers, to
73 allow building these libraries with POSIX threads support:</para>
74
75<screen><userinput remap="pre">sed '/thread_header =/s/@.*@/gthr-posix.h/' \
76 -i libgcc/Makefile.in libstdc++-v3/include/Makefile.in</userinput></screen>
77
78 <para>Create a separate build directory again:</para>
79
80<screen><userinput remap="pre">mkdir -v build
81cd build</userinput></screen>
82
83 <para>Before starting to build GCC, remember to unset any environment
84 variables that override the default optimization flags.</para>
85
86 <para>Now prepare GCC for compilation:</para>
87
88<screen><userinput remap="configure">../configure \
89 --build=$(../config.guess) \
90 --host=$LFS_TGT \
91 --prefix=/usr \
92 CC_FOR_TARGET=$LFS_TGT-gcc \
93 CXX_FOR_TARGET=$LFS_TGT-g++ \
94 LDFLAGS_FOR_TARGET=-L$PWD/$LFS_TGT/libgcc \
95 --with-build-sysroot=$LFS \
96 --enable-initfini-array \
97 --disable-nls \
98 --disable-multilib \
99 --disable-decimal-float \
100 --disable-libatomic \
101 --disable-libgomp \
102 --disable-libquadmath \
103 --disable-libssp \
104 --disable-libvtv \
105 --enable-languages=c,c++</userinput></screen>
106
107 <variablelist>
108 <title>The meaning of the new configure options:</title><!-- WIP -->
109
110 <varlistentry>
111 <term><parameter>-with-build-sysroot=$LFS</parameter></term>
112 <listitem>
113 <para>Normally, using <parameter>--host</parameter> ensures that
114 a cross-compiler is used for building GCC, and that compiler knows
115 that it has to look for headers and libraries in <filename
116 class="directory">$LFS</filename>. But the build system of GCC uses
117 other tools, which are not aware of this location. This switch is
118 needed to have them find the needed files in <filename
119 class="directory">$LFS</filename>, and not on the host.</para>
120 </listitem>
121 </varlistentry>
122
123 <varlistentry>
124 <term><parameter>--enable-initfini-array</parameter></term>
125 <listitem>
126 <para>This option is automatically enabled when building a native
127 compiler with a native compiler on x86. But here, we build with
128 a cross compiler, so we need to explicitly set this option.</para>
129 </listitem>
130 </varlistentry>
131
132 </variablelist>
133
134 <para>Compile the package:</para>
135
136<screen><userinput remap="make">make</userinput></screen>
137
138 <para>Install the package:</para>
139
140<screen><userinput remap="install">make DESTDIR=$LFS install</userinput></screen>
141
142 <para>As a finishing touch, create a utility symlink. Many programs and scripts
143 run <command>cc</command> instead of <command>gcc</command>, which is
144 used to keep programs generic and therefore usable on all kinds of UNIX
145 systems where the GNU C compiler is not always installed. Running
146 <command>cc</command> leaves the system administrator free to decide
147 which C compiler to install:</para>
148
149<screen><userinput remap="install">ln -sv gcc $LFS/usr/bin/cc</userinput></screen>
150
151 </sect2>
152
153 <sect2 role="content">
154 <title/>
155
156 <para>Details on this package are located in
157 <xref linkend="contents-gcc" role="."/></para>
158
159 </sect2>
160
161</sect1>
Note: See TracBrowser for help on using the repository browser.