I'm attempting to build GCC 10.5 for an older version of QNX on an x86 platform in an Ubuntu 20.04 x86_64 environment. I downloaded the gcc-10.5.0.tar.xz
file from GNU's FTP server and ran the following commands:
tar -xvf gcc-10.5.0.tar.xz
cd gcc-10.5.0
./contrib/download_prerequisites
cd ..
mkdir bin-qnx63-i386
cd bin-qnx63-i386
./../gcc-10.5.0/configure $(options)
make
These are the current options in $(options)
:
--host=x86_64-pc-linux-gnu
--target=i386-pc-nto-qnx6.3.0
--prefix=/usr/local/nyab
--program-prefix=nyab-
--disable-multilib
--enable-threads=posix
--enable-tls
--enable-version-specific-runtime-libs
--enable-languages=c,c++
--disable-libada
--disable-libgm2
--enable-default-pie
--enable-werror
--enable-checking
--enable-valgrind-annotations
--with-sysroot=/opt/qnx630/target/qnx6
In addition, I've copied ar
, as
, ld
and ranlib
from the SDK to /usr/local/nyab/i386-pc-nto-qnx6.3.0/bin
as directed here. After an initial failed run, I copied the CRT libraries from the SDK to /usr/local/nyab/i386-pc-nto-qnx6.3.0/lib
as that appeared to be needed as well.
This setup seems to work until I get to the i386-pc-nto-qnx6.3.0/libstdc++-v3
directory where it fails. Looking at config.log
the issue seems to stem from the following line:
/usr/local/nyab/i386-pc-nto-qnx6.3.0/bin/ld: cannot open /opt/qnx630/target/qnx6x86/lib/crtbegin.o: No such file or directory
The correct path is /opt/qnx630/target/qnx6/x86/lib
.
I've attempted to modify the --with-sysroot
option to include trailing slashes, but that seems to have no effect. Next, I created a small C file:
#include <stdio.h>
int main(void) {
printf("Hello, world!\n");
return 0;
}
I passed it to the compiler using the flags of the failing command plus the flag to spit out additional information (formatted for StackOverflow):
/home/nyab/gcc/bin-qnx63-i386/./gcc/xgcc -B/home/nyab/gcc/bin-qnx63-i386/./gcc/ \
-B/usr/local/nyab/i386-pc-nto-qnx6.3.0/bin/ \
-B/usr/local/nyab/i386-pc-nto-qnx6.3.0/lib/ \
-isystem /usr/local/nyab/i386-pc-nto-qnx6.3.0/include \
-isystem /usr/local/nyab/i386-pc-nto-qnx6.3.0/sys-include \
-v -o /tmp/test -g -O2 /tmp/test.c
And found that GCC is creating the incorrect paths (newlines added for the incorrect paths):
...
COLLECT_GCC_OPTIONS='-B' '/home/nyab/gcc/bin-qnx63-i386/./gcc/' '-B' '/usr/local/nyab/i386-pc-nto-qnx6.3.0/bin/' '-B' '/usr/local/nyab/i386-pc-nto-qnx6.3.0/lib/' '-isystem' '/usr/local/nyab/i386-pc-nto-qnx6.3.0/include' '-isystem' '/usr/local/nyab/i386-pc-nto-qnx6.3.0/sys-include' '-v' '-o' '/tmp/test' '-g' '-O2' '-mtune=generic' '-march=pentiumpro'
/home/nyab/gcc/bin-qnx63-i386/./gcc/collect2 -V -Y P,
/opt/qnx630/target/qnx6x86/lib
-Qy -m i386nto --dynamic-linker /usr/lib/ldqnx.so.2 -o /tmp/test /usr/local/nyab/i386-pc-nto-qnx6.3.0/lib/crt1.o /usr/local/nyab/i386-pc-nto-qnx6.3.0/lib/crti.o
/opt/qnx630/target/qnx6x86/lib/crtbegin.o
-L/home/nyab/gcc/bin-qnx63-i386/./gcc -L/usr/local/nyab/i386-pc-nto-qnx6.3.0/bin -L/usr/local/nyab/i386-pc-nto-qnx6.3.0/lib /tmp/ccb1wUOU.o -lgcc -lc -lgcc /usr/local/nyab/i386-pc-nto-qnx6.3.0/lib/crtend.o /usr/local/nyab/i386-pc-nto-qnx6.3.0/lib/crtn.o
...
I have confirmed crtbegin.o
is in /usr/local/nyab/i386-pc-nto-qnx6.3.0/lib
although it was copied from /opt/qnx630/target/qnx6/x86/lib
. Does anyone know where I went wrong or what to try next?
Short answer
Modify SYSROOT_SUFFIX_SPEC
in <src-dir>/gcc/config/i386/nto.h
to /86
.
Long answer
GCC uses spec files to determine how to call itself and other programs with their appropriate command line arguments. Thorough investigation of <src-dir>/gcc/gcc.c
will show you how these files are created or read in to the program. Since we fail during linker invocation, the LINK_SPEC
definition matters here. For this QNX build, its found in <src-dir>/gcc/config/i386/nto.h
. The two lines that matter are:
...
%{!YP,*:%{p:-Y P,%R/lib} \
%{!p:-Y P,%R/lib}} \
...
The spec language reference linked earlier says %R
is "the concatenation of target_system_root and target_sysroot_suffix." The target_sysroot_suffix
is actually defined in the nto.h
file under the SYSROOT_SUFFIX_SPEC
preprocessor macro. Cross referencing this definition with other definitions in mti-linux.h
and st.h
, the specification in nto.h
is missing the forward slash at the beginning. Changing the value from x86
to /x86
will get you past this issue.