source: chapter05/gcc-pass1.xml@ 746175a

xry111/loongarch xry111/loongarch-12.2
Last change on this file since 746175a was 4ac095c7, checked in by Xi Ruoyao <xry111@…>, 8 months ago

loongarch: gcc: Apply an upstream change to prevent the linker from generating illegal instructions

I've proposed a backport of the change to GCC 13.3 but no response yet.
But even if the proposal is rejected I'd still have no choice but
backporting downstream. So just do it.

  • Property mode set to 100644
File size: 8.7 KB
Line 
1<?xml version="1.0" encoding="UTF-8"?>
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-pass1" role="wrap" xreflabel="gcc-pass1">
9 <?dbhtml filename="gcc-pass1.html"?>
10
11 <sect1info condition="script">
12 <productname>gcc-pass1</productname>
13 <productnumber>&gcc-version;</productnumber>
14 <address>&gcc-url;</address>
15 </sect1info>
16
17 <title>GCC-&gcc-version; - Pass 1</title>
18
19 <indexterm zone="ch-tools-gcc-pass1">
20 <primary sortas="a-GCC">GCC</primary>
21 <secondary>tools, pass 1</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-tmpp1-sbu;</seg>
37 <seg>&gcc-tmpp1-du;</seg>
38 </seglistitem>
39 </segmentedlist>
40
41 </sect2>
42
43 <sect2 role="installation">
44 <title>Installation of Cross GCC</title>
45
46 <!-- https://gcc.gnu.org/r14-4674 -->
47 <para>At first, fix an issue producing illegal instructions in linked
48 executables and shared libraries with GCC &gcc-version; and
49 Binutils-2.42:</para>
50
51 <screen><userinput remap='pre'>sed -e '/ASM_OUTPUT_ALIGN_WITH_NOP/,+1d' \
52 -i gcc/config/loongarch/loongarch.h</userinput></screen>
53
54 <para>GCC requires the GMP, MPFR and MPC packages. As these packages may
55 not be included in your host distribution, they will be built with
56 GCC. Unpack each package into the GCC source directory and rename the
57 resulting directories so the GCC build procedures will automatically
58 use them:</para>
59
60 <note><para>There are frequent misunderstandings about this chapter. The
61 procedures are the same as every other chapter, as explained earlier (<xref
62 linkend='buildinstr'/>). First, extract the gcc-&gcc-version; tarball from the sources
63 directory, and then change to the directory created. Only then should you
64 proceed with the instructions below.</para></note>
65
66<screen><userinput remap="pre">tar -xf ../mpfr-&mpfr-version;.tar.xz
67mv -v mpfr-&mpfr-version; mpfr
68tar -xf ../gmp-&gmp-version;.tar.xz
69mv -v gmp-&gmp-version; gmp
70tar -xf ../mpc-&mpc-version;.tar.gz
71mv -v mpc-&mpc-version; mpc</userinput></screen>
72
73 <para>Set the default directory name for
74 64-bit libraries to <quote>lib</quote>:</para>
75
76<screen><userinput remap="pre">sed -e 's/lib64/lib/' \
77 -i.orig gcc/config/loongarch/{t-linux,linux.h}</userinput></screen>
78
79 <para>The GCC documentation recommends building GCC
80 in a dedicated build directory:</para>
81
82<screen><userinput remap="pre">mkdir -v build
83cd build</userinput></screen>
84
85 <para>Prepare GCC for compilation:</para>
86
87<screen><userinput remap="configure">../configure \
88 --target=$LFS_TGT \
89 --prefix=$LFS/tools \
90 --with-glibc-version=&glibc-version; \
91 --with-sysroot=$LFS \
92 --with-newlib \
93 --without-headers \
94 --enable-default-pie \
95 --enable-default-ssp \
96 --disable-nls \
97 --disable-shared \
98 --disable-multilib \
99 --disable-threads \
100 --disable-libatomic \
101 --disable-libgomp \
102 --disable-libquadmath \
103 --disable-libssp \
104 --disable-libvtv \
105 --disable-libstdcxx \
106 --enable-languages=c,c++</userinput></screen>
107 <variablelist>
108 <title>The meaning of the configure options:</title>
109
110 <varlistentry>
111 <term><parameter>--with-glibc-version=&glibc-version;</parameter></term>
112 <listitem>
113 <para>This option specifies the version of Glibc which will be
114 used on the target. It is not relevant to the libc of the host
115 distro because everything compiled by pass1 GCC will run in the
116 chroot environment, which is isolated from libc of the host
117 distro.</para>
118 </listitem>
119 </varlistentry>
120
121 <varlistentry>
122 <term><parameter>--with-newlib</parameter></term>
123 <listitem>
124 <para>Since a working C library is not yet available, this ensures
125 that the inhibit_libc constant is defined when building libgcc. This prevents
126 the compiling of any code that requires libc support.</para>
127 </listitem>
128 </varlistentry>
129
130 <varlistentry>
131 <term><parameter>--without-headers</parameter></term>
132 <listitem>
133 <para>When creating a complete cross-compiler, GCC requires
134 standard headers compatible with the target system. For our
135 purposes these headers will not be needed. This switch prevents
136 GCC from looking for them.</para>
137 </listitem>
138 </varlistentry>
139
140 <varlistentry>
141 <term><parameter>--enable-default-pie and
142 --enable-default-ssp</parameter></term>
143 <listitem>
144 <para>Those switches allow GCC to compile programs with
145 some hardening security features (more information on those in
146 the <xref linkend="pie-ssp-info"/> in chapter 8) by default. The
147 are not strictly needed at this stage, since the compiler will
148 only produce temporary executables. But it is cleaner to have the
149 temporary packages be as close as possible to the final ones.
150 </para>
151 </listitem>
152 </varlistentry>
153
154 <varlistentry>
155 <term><parameter>--disable-shared</parameter></term>
156 <listitem>
157 <para>This switch forces GCC to link its internal libraries
158 statically. We need this because the shared libraries require Glibc,
159 which is not yet installed on the target system.</para>
160 </listitem>
161 </varlistentry>
162
163 <varlistentry>
164 <term><parameter>--disable-multilib</parameter></term>
165 <listitem>
166 <para>On LoongArch, LFS does not support a multilib configuration.</para>
167 </listitem>
168 </varlistentry>
169
170 <varlistentry>
171 <term><parameter>--disable-threads,
172 --disable-libatomic, --disable-libgomp,
173 --disable-libquadmath, --disable-libssp, --disable-libvtv,
174 --disable-libstdcxx</parameter></term>
175 <listitem>
176 <para>These switches disable support for
177 threading, libatomic, libgomp, libquadmath, libssp,
178 libvtv, and the C++ standard library respectively. These features
179 may fail to compile when building a cross-compiler and are not
180 necessary for the task of cross-compiling the temporary libc.</para>
181 </listitem>
182 </varlistentry>
183
184 <varlistentry>
185 <term><parameter>--enable-languages=c,c++</parameter></term>
186 <listitem>
187 <para>This option ensures that only the C and C++ compilers are built.
188 These are the only languages needed now.</para>
189 </listitem>
190 </varlistentry>
191
192 </variablelist>
193
194 <para>Compile GCC by running:</para>
195
196<screen><userinput remap="make">make</userinput></screen>
197
198 <para>Install the package:</para>
199
200 <screen><userinput remap="install">make install</userinput></screen>
201
202 <para>This build of GCC has installed a couple of internal system
203 headers. Normally one of them, <filename>limits.h</filename>, would in turn
204 include the corresponding system <filename>limits.h</filename> header, in
205 this case, <filename>$LFS/usr/include/limits.h</filename>. However, at the
206 time of this build of GCC <filename>$LFS/usr/include/limits.h</filename>
207 does not exist, so the internal header that has just been installed is a
208 partial, self-contained file and does not include the extended features of
209 the system header. This is adequate for building Glibc, but the full
210 internal header will be needed later. Create a full version of the internal
211 header using a command that is identical to what the GCC build system does
212 in normal circumstances:</para>
213
214 <note>
215 <para>The command below shows an example of nested command substitution
216 using two methods: backquotes and a <literal>$()</literal> construct.
217 It could be rewritten using the same method for both substitutions,
218 but is shown this way to demonstrate how they can be mixed. Generally
219 the <literal>$()</literal> method is preferred.</para>
220 </note>
221
222<screen><userinput remap="install">cd ..
223cat gcc/limitx.h gcc/glimits.h gcc/limity.h > \
224 `dirname $($LFS_TGT-gcc -print-libgcc-file-name)`/include/limits.h</userinput></screen>
225 </sect2>
226
227 <sect2 role="content">
228 <title/>
229
230 <para>Details on this package are located in
231 <xref linkend="contents-gcc" role="."/></para>
232
233 </sect2>
234
235</sect1>
Note: See TracBrowser for help on using the repository browser.