source: chapter06/gcc-pass2.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: 7.4 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-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>First fix a problem with the latest version of glibc:</para>
47
48 <screen><userinput remap="pre">patch -Np1 -i ../&gcc-upstream-fixes-patch;</userinput></screen>
49-->
50
51 <!-- https://gcc.gnu.org/r14-4674 -->
52 <para>Again, fix an issue producing illegal instructions in linked
53 executables and shared libraries with GCC &gcc-version; and
54 Binutils-2.42:</para>
55
56 <screen><userinput remap='pre'>sed -e '/ASM_OUTPUT_ALIGN_WITH_NOP/,+1d' \
57 -i gcc/config/loongarch/loongarch.h</userinput></screen>
58
59 <para>As in the first build of GCC, the GMP, MPFR, and MPC packages are
60 required. Unpack the tarballs and move them into the required directories:</para>
61
62<screen><userinput remap="pre">tar -xf ../mpfr-&mpfr-version;.tar.xz
63mv -v mpfr-&mpfr-version; mpfr
64tar -xf ../gmp-&gmp-version;.tar.xz
65mv -v gmp-&gmp-version; gmp
66tar -xf ../mpc-&mpc-version;.tar.gz
67mv -v mpc-&mpc-version; mpc</userinput></screen>
68
69 <para>Set the default directory name for
70 64-bit libraries to <quote>lib</quote>:</para>
71
72<screen><userinput remap="pre">sed -e 's/lib64/lib/' \
73 -i.orig gcc/config/loongarch/{t-linux,linux.h}</userinput></screen>
74
75 <para>Override the building rule of libgcc and libstdc++ headers, to
76 allow building these libraries with POSIX threads support:</para>
77
78<screen><userinput remap="pre">sed '/thread_header =/s/@.*@/gthr-posix.h/' \
79 -i libgcc/Makefile.in libstdc++-v3/include/Makefile.in</userinput></screen>
80
81 <para>Create a separate build directory again:</para>
82
83<screen><userinput remap="pre">mkdir -v build
84cd build</userinput></screen>
85
86 <para>Before starting to build GCC, remember to unset any environment
87 variables that override the default optimization flags.</para>
88
89 <para>Now prepare GCC for compilation:</para>
90
91<screen><userinput remap="configure">../configure \
92 --build=$(../config.guess) \
93 --host=$LFS_TGT \
94 --target=$LFS_TGT \
95 LDFLAGS_FOR_TARGET=-L$PWD/$LFS_TGT/libgcc \
96 --prefix=/usr \
97 --with-build-sysroot=$LFS \
98 --enable-default-pie \
99 --enable-default-ssp \
100 --disable-nls \
101 --disable-multilib \
102 --disable-libatomic \
103 --disable-libgomp \
104 --disable-libquadmath \
105 --disable-libsanitizer \
106 --disable-libssp \
107 --disable-libvtv \
108 --enable-languages=c,c++</userinput></screen>
109
110 <variablelist>
111 <title>The meaning of the new configure options:</title><!-- WIP -->
112
113 <varlistentry>
114 <term><parameter>--with-build-sysroot=$LFS</parameter></term>
115 <listitem>
116 <para>Normally, using <parameter>--host</parameter> ensures that
117 a cross-compiler is used for building GCC, and that compiler knows
118 that it has to look for headers and libraries in <filename
119 class="directory">$LFS</filename>. But the build system for GCC uses
120 other tools, which are not aware of this location. This switch is
121 needed so those tools will find the needed files in <filename
122 class="directory">$LFS</filename>, and not on the host.</para>
123 </listitem>
124 </varlistentry>
125
126 <varlistentry>
127 <term><parameter>--target=$LFS_TGT</parameter></term>
128 <listitem>
129 <para>We are cross-compiling GCC, so it's impossible to build
130 target libraries (<filename class="libraryfile">libgcc</filename>
131 and <filename class="libraryfile">libstdc++</filename>) with the
132 previously compiled GCC binaries&mdash;those binaries won't run on the
133 host. The GCC build system will attempt to use the host's
134 C and C++ compilers as a workaround by default.
135 Building the GCC target libraries with a different
136 version of GCC is not supported, so using the host's compilers may cause
137 the build to fail. This parameter ensures the libraries are built by GCC
138 pass 1.</para>
139 </listitem>
140 </varlistentry>
141
142 <varlistentry>
143 <term><parameter>LDFLAGS_FOR_TARGET=...</parameter></term>
144 <listitem>
145 <para>Allow <filename class="libraryfile">libstdc++</filename> to
146 use the shared <filename class="libraryfile">libgcc</filename> being
147 built in this pass, instead of the static version that was built in GCC
148 pass 1. This is necessary to support C++ exception
149 handling.</para>
150 </listitem>
151 </varlistentry>
152
153 <varlistentry>
154 <term><parameter>--disable-libsanitizer</parameter></term>
155 <listitem>
156 <para>Disable GCC sanitizer runtime libraries. They are not
157 needed for the temporary installation. This switch is necessary
158 to build GCC without
159 <systemitem class='library'>libcrypt</systemitem> installed for
160 the target. In <xref linkend='ch-tools-gcc-pass1'/> it was
161 implied by <parameter>--disable-libstdcxx</parameter>, but now we
162 have to explicitly pass it.</para>
163 </listitem>
164 </varlistentry>
165
166 </variablelist>
167
168 <para>Compile the package:</para>
169
170<screen><userinput remap="make">make</userinput></screen>
171
172 <para>Install the package:</para>
173
174<screen><userinput remap="install">make DESTDIR=$LFS install</userinput></screen>
175
176 <para>As a finishing touch, create a utility symlink. Many programs and scripts
177 run <command>cc</command> instead of <command>gcc</command>, which is
178 used to keep programs generic and therefore usable on all kinds of UNIX
179 systems where the GNU C compiler is not always installed. Running
180 <command>cc</command> leaves the system administrator free to decide
181 which C compiler to install:</para>
182
183<screen><userinput remap="install">ln -sv gcc $LFS/usr/bin/cc</userinput></screen>
184
185 </sect2>
186
187 <sect2 role="content">
188 <title/>
189
190 <para>Details on this package are located in
191 <xref linkend="contents-gcc" role="."/></para>
192
193 </sect2>
194
195</sect1>
Note: See TracBrowser for help on using the repository browser.