Porting packages to MIPS - ParabolaWiki

# Porting packages to MIPS

This page lists some problems and potential solutions when porting Parabola packages to MIPS.

## Before trying to fix it

- check if the problem occurs with newest release of the package
- in case of build errors, check on x86_64, typically the error will occur and will be quicker to fix
- check if other distros supporting MIPS n32 have a patch for it
- check if there are optional fixes, patches or bugs reported for MIPS o32, SPARC or other architectures
- if it's observed at runtime, check if package has automated tests which similarly fail

## Linking with static libraries

The following error occurred when compiling a package:

    /usr/bin/ld: /usr/lib/gcc/mips64el-unknown-linux-gnu/4.5.2/../../../libc-client.a(osdep.o): \
    relocation R_MIPS_HI16 against `__gnu_local_gp' can not be used when making a shared object; recompile with -fPIC

The bug is in the package containing the mentioned library, in this case imap (`pacman -Qo /usr/lib/gcc/mips64el-unknown-linux-gnu/4.5.2/../../../libc-client.a` finds the package name).

Note: Like x86_64, mips64el requires compiling shared libraries with -fPIC, but in this case linking a shared library with a static one was tried and failed. If the package supports x86_64, PKGBUILD probably already adds this option for all compiles on x86_64, enabling it also on mips64el would solve the problem.

A proper fix would be to make shared libraries instead of static ones.

## Bus error when running the package

Accessing unaligned data causes such error. If a package works on o32 and typical 64-bit architectures requiring alignment, the problem is probably in having doubles aligned to 4 instead of 8 bytes.

Use gdb to find the code causing the problem, i.e. making an unaligned pointer and passing it to code using it as a structure containing a double. The problem would be fixed by adding padding to make this structure aligned to 8 bytes.

Example upstream bug report: [1].

## "Illegal" instruction when running the package

Use gdb to disassemble the code. Instructions like `madd.s` cause it when used with a NaN in an argument.

A simple workaround is to compile the package with `-march=mips3` in CFLAGS instead of `-march=loongson2f` so these instructions won't be used.

Example: [2].

## Linker out of memory

This is more common when debug symbols are enabled (`-ggdb` in CFLAGS). Linker writes that it cannot allocate memory, or just fails with segmentation violation.

Adding `-Wl,--reduce-memory-overhead -Wl,--no-keep-memory` to LDFLAGS makes it use less memory, fixing the problem in at least one case. It makes linking slower, so it shouldn't be enabled when not needed.

Example: [3].

## `soelim` or another command not found by `configure`

There is nothing MIPS-specific in this problem, it's caused by Arch packages being built not in a clean chroot, thus having installed packages not specified in `depends` or `makedepends`.

Add the package providing the missing command to `makedepends`.

Sometimes a package is missing despite being in the `base` or `base-devel` group, it should be just installed in the chroot. If it's being removed by `libremakepkg -c`, then it (or its dependency) should be added to `/etc/libretools.d/cleansystem` (and a bug should be reported).

## `config.guess` not recognizing the architecture

Pass the `--build=$CHOST` or `--host=$CHOST` argument to `./configure`, depending on the error message. In rare cases `--target=$CHOST` should be used, but it's probably a bug in the package since most programs don't have a target system (it's only useful for compilers).

There is another reason for this script to fail: it needs the C compiler to determine endian (eb or el in the architecture name) and fails if the compiler fails. This typically occurs when updating gcc after its dependencies changing SONAME (the fix described in the previous paragraph would make it fail more clearly in another configure test).

## Undeclared function

This usually isn't MIPS-specific. Check the man page of the function mentioned in the error message, the source file probably doesn't include the header where POSIX states it to be declared (older GCC and GLIBC included it in other headers) or, if it's a GNU extension, declares _GNU_SOURCE after including a header. Patch it to fix this.

Category:

- MIPS