This thread is continuation on me trying to compile GCC for Platform SDK / Sailfish SDK. I was so impressed by the style of the blog that I decided to try it myself. Let’s see how this goes…
Quick recap:
- Read the blog
- Find the bug
- Get the patch
- Install Platform SDK (and aarch64 target since that triggers the bug)
- Download gcc sources
- Roll up sleeves!
I had already tried most of the things @flypig kindly suggested earlier, but the first issue comes from the project structure: there is no rpm
folder to contain .spec
file, so compilation attempts end up like this:
PlatformSDK $ mb2 build -d -p
Fatal: No RPM SPEC or YAML file found in '/home/matti/PSDK/sailfishos-gcc/rpm/'
Future me here! This was roughly the outcome with trying sfdk build
too – I knew it would insist on having one single .spec
file inside rpm/
, so I changed to Platform SDK in hopes that mb2
would pick it up – that wasn’t the case…
(Don’t mind the commit hash, I’m not sure if I was already on a new wip branch or something.)
From there, I created the folder and copied gcc.spec
there:
PlatformSDK $ mb2 build -d -p
Setting version: 8.3.0.7+copysignf.20230831155339.0034f4d
[...]
Building target platforms: aarch64-meego-linux-gnu
Building for target aarch64-meego-linux-gnu
error: Bad source: /home/matti/PSDK/sailfishos-gcc/rpm/gcc8-hack.patch: No such file or directory
Then I copied the patches there too:
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.tOqQQQ
+ umask 022
+ cd /home/matti/PSDK/sailfishos-gcc
+ LANG=C
+ export LANG
+ unset DISPLAY
+ echo 'Patch #0 (gcc8-hack.patch):'
Patch #0 (gcc8-hack.patch):
+ patch --no-backup-if-mismatch -p0 -b --suffix .hack~ --fuzz=2
can't find file to patch at input line 3
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|--- libada/Makefile.in.jj 2009-01-14 12:07:35.000000000 +0100
|+++ libada/Makefile.in 2009-01-15 14:25:33.000000000 +0100
--------------------------
File to patch: ^C
At this point I started messing around with rpmbuild
, with gradual progress:
PlatformSDK $ rpmbuild -bp gcc.spec
error: Bad source: /home/matti/rpmbuild/SOURCES/gcc-arm-src-snapshot-8.3-2019.03.tar.xz: No such file or directory
So I did that.
error: Bad source: /home/matti/rpmbuild/SOURCES/gcc8-hack.patch: No such file or directory
And that…
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.6GLUG3
[...]
Patch #0 (gcc8-hack.patch):
+ /usr/bin/patch --no-backup-if-mismatch -p0 -b --suffix .hack~ --fuzz=0
[...]
Patch #15 (gcc8-reproducible-builds-buildid-for-checksum.patch):
+ /usr/bin/patch --no-backup-if-mismatch -p0 -b --suffix .reproducible-builds-buildid-for-checksum~ --fuzz=0
patching file gcc/c-family/c-pch.c
patching file gcc/genchecksum.c
+ echo 'Sailfish OS gcc 8.3.0-7'
+ sed -i '/UInteger Var(dwarf_version)/s/Init(2)/Init(4)/' gcc/common.opt
+ sed -i 's/\(may be either 2 or 3 or 4; the default version is \)2\./\14./' gcc/doc/invoke.texi
[...]
Finally, the patches are in! With some testing, I found out that -p1
is needed with that patch. So let’s add the new patch and try again:
$ cat gcc.spec
[...]
Patch15: gcc8-reproducible-builds-buildid-for-checksum.patch
Patch16: gcc8-copyscanf.patch # new line
[...]
%patch15 -p0 -b .reproducible-builds-buildid-for-checksum~
%patch16 -p1 -b .copyscanf~ # new line
[...]
Patch #15 (gcc8-reproducible-builds-buildid-for-checksum.patch):
+ /usr/bin/patch --no-backup-if-mismatch -p0 -b --suffix .reproducible-builds-buildid-for-checksum~ --fuzz=0
patching file gcc/c-family/c-pch.c
patching file gcc/genchecksum.c
+ echo 'Patch #16 (gcc8-copyscanf.patch):'
Patch #16 (gcc8-copyscanf.patch):
+ /usr/bin/patch --no-backup-if-mismatch -p1 -b --suffix .copyscanf~ --fuzz=0
patching file gcc/ChangeLog
Hunk #1 FAILED at 1.
1 out of 1 hunk FAILED -- saving rejects to file gcc/ChangeLog.rej
patching file gcc/config/aarch64/aarch64.md
Hunk #1 FAILED at 189.
Hunk #2 succeeded at 5438 (offset 11 lines).
1 out of 2 hunks FAILED -- saving rejects to file gcc/config/aarch64/aarch64.md.rej
patching file gcc/config/aarch64/iterators.md
Hunk #1 succeeded at 581 (offset 3 lines).
Hunk #2 succeeded at 668 (offset 3 lines).
patching file gcc/testsuite/ChangeLog
Hunk #1 FAILED at 1.
1 out of 1 hunk FAILED -- saving rejects to file gcc/testsuite/ChangeLog.rej
patching file gcc/testsuite/gcc.target/aarch64/pr90075.c
error: Bad exit status from /var/tmp/rpm-tmp.TW3siP (%prep)
Close! At this point I manually modified the patch so that it would finally apply! My approach – without any research on patching patches – I decided to make a git repo of the SOURCES
folder, apply the first 15 patches, commit the files and start from there. Then I just tried to apply the patch, see the results, adjust the patch, reset the repository (this was the lifesaver trick!) and try applying it again. I am not going to replicate any of that patchwork (ha!) here, just tons of text editing, until finally:
PlatformSDK $ rpmbuild -bp gcc.spec
[...]
Patch #16 (gcc8-copyscanf.patch):
+ /usr/bin/patch --no-backup-if-mismatch -p1 -b --suffix .copyscanf~ --fuzz=0
patching file gcc/ChangeLog
patching file gcc/config/aarch64/aarch64.md
Hunk #1 succeeded at 194 (offset -2 lines).
Hunk #2 succeeded at 5439 (offset 11 lines).
patching file gcc/config/aarch64/iterators.md
Hunk #1 succeeded at 581 (offset 3 lines).
Hunk #2 succeeded at 668 (offset 3 lines).
patching file gcc/testsuite/ChangeLog
patching file gcc/testsuite/gcc.target/aarch64/pr90075.c
+ echo 'Sailfish OS gcc 8.3.0-7'
+ sed -i '/UInteger Var(dwarf_version)/s/Init(2)/Init(4)/' gcc/common.opt
+ sed -i 's/\(may be either 2 or 3 or 4; the default version is \)2\./\14./' gcc/doc/invoke.texi
+ cp -a libstdc++-v3/config/cpu/i486/atomicity.h libstdc++-v3/config/cpu/i386/atomicity.h
+ perl -pi -e 's/^all: all-redirect/ifeq (\$(MULTISUBDIR),)\nall: all-redirect\nelse\nall:\n\techo Multilib libjava build disabled\nendif/' libjava/Makefile.in
Can't open libjava/Makefile.in: No such file or directory.
+ perl -pi -e 's/^install: install-redirect/ifeq (\$(MULTISUBDIR),)\ninstall: install-redirect\nelse\ninstall:\n\techo Multilib libjava install disabled\nendif/' libjava/Makefile.in
Can't open libjava/Makefile.in: No such file or directory.
+ perl -pi -e 's/^check: check-redirect/ifeq (\$(MULTISUBDIR),)\ncheck: check-redirect\nelse\ncheck:\n\techo Multilib libjava check disabled\nendif/' libjava/Makefile.in
Can't open libjava/Makefile.in: No such file or directory.
+ perl -pi -e 's/^all: all-recursive/ifeq (\$(MULTISUBDIR),)\nall: all-recursive\nelse\nall:\n\techo Multilib libjava build disabled\nendif/' libjava/Makefile.in
Can't open libjava/Makefile.in: No such file or directory.
+ perl -pi -e 's/^install: install-recursive/ifeq (\$(MULTISUBDIR),)\ninstall: install-recursive\nelse\ninstall:\n\techo Multilib libjava install disabled\nendif/' libjava/Makefile.in
Can't open libjava/Makefile.in: No such file or directory.
+ perl -pi -e 's/^check: check-recursive/ifeq (\$(MULTISUBDIR),)\ncheck: check-recursive\nelse\ncheck:\n\techo Multilib libjava check disabled\nendif/' libjava/Makefile.in
Can't open libjava/Makefile.in: No such file or directory.
+ ./contrib/gcc_update --touch
./contrib/gcc_update: line 203: make: command not found
+ LC_ALL=C
+ sed -i -e 's/\xa0/ /' gcc/doc/options.texi
+ RPM_EC=0
++ jobs -p
+ exit 0
Victory!
It’s quite obvious that the rpmbuild
route is a dead end, but ultimately I only needed to see how well the patch would apply. And that’s just as far as I got! And not an inch further…
At this point I decided that it was good enough for pushing the changes and making the pull request! I guess it won’t be merged as-is, but it should compile at least.
Oh. (Oh no.)
I had an epiphany, just now as I’m writing this.
I may not be supposed to compile it with mb2
which targets the target architecture, but instead compile it “normally” inside PlatformSDK, so that the compilation targets the Platform SDK. That makes more sense… Oh well, I still think I’ll leave it here, unless someone can point me to right direction!