Skip to content

Commit

Permalink
Make gcc-aarch64 reproducible (#366)
Browse files Browse the repository at this point in the history
This fixes ollieparanoid/binary-package-repo#1

GCC generates hardlinks between files `A` and `B` in its `make install` step. The problem is, that `tar` randomly packages `A` as full binary, and links `B` to `A`, or the other way around! I was able to reproduce this issue consistently when re-building `gcc-aarch64` on Travis CI (interestingly, this did not appear for `gcc-armhf`).

The fix is, to delete `B` and create a symlink `B` that points to `A` instead.
  • Loading branch information
Oliver Smith committed Aug 12, 2017
1 parent 55b32da commit a65e7d0
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 42 deletions.
57 changes: 36 additions & 21 deletions cross/gcc-aarch64/APKBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,41 @@ LANG_FORTRAN=false
LANG_ADA=false
options="!strip !tracedeps"

# Wrap the package function, to make the resulting package
# lazy-reproducible
package() {
# Repack the *.a files to be reproducible (see #64)
_temp="$_builddir"/_reproducible-patch
cd "$_builddir"
for f in $(find -name '*.a'); do
# Copy to a temporary folder
echo "Repack $f to be reproducible"
mkdir -p "$_temp"
cd "$_temp"
cp "$_builddir"/"$f" .

# Repack with a sorted file order
ar x *.a
rm *.a
ar r sorted.a $(find -name '*.o' | sort)

# Copy back and clean up
cp -v sorted.a "$_builddir"/"$f"
cd ..
rm -r "$_temp"
done

# Unmodified package function from the gcc APKBUILD
_package

# Workaround for: postmarketOS/binary-package-repo#1
echo "Replacing hardlinks with symlinks"
rm -v "$pkgdir"/usr/bin/"$CTARGET"-c++
ln -s -v /usr/bin/"$CTARGET"-g++ "$pkgdir"/usr/bin/"$CTARGET"-c++
rm -v "$pkgdir"/usr/bin/"$CTARGET"-gcc-"$pkgver"
ln -s -v /usr/bin/"$CTARGET"-gcc "$pkgdir"/usr/bin/"$CTARGET"-gcc-"$pkgver"
}

pkgname="gcc-aarch64"
pkgver=6.4.0
[ "$BOOTSTRAP" = "nolibc" ] && pkgname="gcc-pass2"
Expand Down Expand Up @@ -320,27 +355,7 @@ build() {
make
}

package() {
# Repack the *.a files to be reproducible (see #64)
_temp="$_builddir"/_reproducible-patch
cd "$_builddir"
for f in $(find -name '*.a'); do
# Copy to a temporary folder
echo "Repack $f to be reproducible"
mkdir -p "$_temp"
cd "$_temp"
cp "$_builddir"/"$f" .

# Repack with a sorted file order
ar x *.a
rm *.a
ar r sorted.a $(find -name '*.o' | sort)

# Copy back and clean up
cp -v sorted.a "$_builddir"/"$f"
cd ..
rm -r "$_temp"
done
_package() {
cd "$_builddir"
make -j1 DESTDIR="${pkgdir}" install

Expand Down
57 changes: 36 additions & 21 deletions cross/gcc-armhf/APKBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,41 @@ LANG_FORTRAN=false
LANG_ADA=false
options="!strip !tracedeps"

# Wrap the package function, to make the resulting package
# lazy-reproducible
package() {
# Repack the *.a files to be reproducible (see #64)
_temp="$_builddir"/_reproducible-patch
cd "$_builddir"
for f in $(find -name '*.a'); do
# Copy to a temporary folder
echo "Repack $f to be reproducible"
mkdir -p "$_temp"
cd "$_temp"
cp "$_builddir"/"$f" .

# Repack with a sorted file order
ar x *.a
rm *.a
ar r sorted.a $(find -name '*.o' | sort)

# Copy back and clean up
cp -v sorted.a "$_builddir"/"$f"
cd ..
rm -r "$_temp"
done

# Unmodified package function from the gcc APKBUILD
_package

# Workaround for: postmarketOS/binary-package-repo#1
echo "Replacing hardlinks with symlinks"
rm -v "$pkgdir"/usr/bin/"$CTARGET"-c++
ln -s -v /usr/bin/"$CTARGET"-g++ "$pkgdir"/usr/bin/"$CTARGET"-c++
rm -v "$pkgdir"/usr/bin/"$CTARGET"-gcc-"$pkgver"
ln -s -v /usr/bin/"$CTARGET"-gcc "$pkgdir"/usr/bin/"$CTARGET"-gcc-"$pkgver"
}

pkgname="gcc-armhf"
pkgver=6.4.0
[ "$BOOTSTRAP" = "nolibc" ] && pkgname="gcc-pass2"
Expand Down Expand Up @@ -320,27 +355,7 @@ build() {
make
}

package() {
# Repack the *.a files to be reproducible (see #64)
_temp="$_builddir"/_reproducible-patch
cd "$_builddir"
for f in $(find -name '*.a'); do
# Copy to a temporary folder
echo "Repack $f to be reproducible"
mkdir -p "$_temp"
cd "$_temp"
cp "$_builddir"/"$f" .

# Repack with a sorted file order
ar x *.a
rm *.a
ar r sorted.a $(find -name '*.o' | sort)

# Copy back and clean up
cp -v sorted.a "$_builddir"/"$f"
cd ..
rm -r "$_temp"
done
_package() {
cd "$_builddir"
make -j1 DESTDIR="${pkgdir}" install

Expand Down

0 comments on commit a65e7d0

Please sign in to comment.