Skip to content

Commit df9d4ff

Browse files
committed
unix: support building for mips[el]-unknown-linux-gnu
The builds complete successfully. Whether the binaries work or not, I don't know. I ran into issues getting the mips64 builds working. I think we're not passing the triple name properly because we're running into linker errors. I dunno. We can deal with this triple later.
1 parent 9306f67 commit df9d4ff

8 files changed

+235
-19
lines changed

cpython-unix/build-cpython.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,21 @@ if [ "${BUILD_TRIPLE}" != "${TARGET_TRIPLE}" ]; then
607607
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} ac_cv_file__dev_ptc=no"
608608
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} ac_cv_file__dev_ptmx=no"
609609
;;
610+
mips-unknown-linux-gnu)
611+
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} ac_cv_buggy_getaddrinfo=no"
612+
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} ac_cv_file__dev_ptc=no"
613+
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} ac_cv_file__dev_ptmx=no"
614+
;;
615+
mipsel-unknown-linux-gnu)
616+
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} ac_cv_buggy_getaddrinfo=no"
617+
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} ac_cv_file__dev_ptc=no"
618+
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} ac_cv_file__dev_ptmx=no"
619+
;;
620+
mips64el-unknown-linux-gnuabi64)
621+
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} ac_cv_buggy_getaddrinfo=no"
622+
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} ac_cv_file__dev_ptc=no"
623+
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} ac_cv_file__dev_ptmx=no"
624+
;;
610625
x86_64-unknown-linux-musl)
611626
;;
612627
*)

cpython-unix/build-libX11.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ if [ "${BUILD_TRIPLE}" != "${TARGET_TRIPLE}" ]; then
5757
i686-unknown-linux-gnu)
5858
EXTRA_FLAGS="${EXTRA_FLAGS} --enable-malloc0returnsnull"
5959
;;
60+
mips-unknown-linux-gnu)
61+
EXTRA_FLAGS="${EXTRA_FLAGS} --enable-malloc0returnsnull"
62+
;;
63+
mipsel-unknown-linux-gnu)
64+
EXTRA_FLAGS="${EXTRA_FLAGS} --enable-malloc0returnsnull"
65+
;;
66+
mips64el-unknown-linux-gnuabi64)
67+
EXTRA_FLAGS="${EXTRA_FLAGS} --enable-malloc0returnsnull"
68+
;;
6069
*)
6170
echo "cross-compiling but malloc(0) override not set; failures possible"
6271
;;
@@ -73,6 +82,15 @@ case "${TARGET_TRIPLE}" in
7382
armv7-unknown-linux-gnueabihf)
7483
CC_FOR_BUILD=gcc
7584
;;
85+
mips-unknown-linux-gnu)
86+
CC_FOR_BUILD=gcc
87+
;;
88+
mipsel-unknown-linux-gnu)
89+
CC_FOR_BUILD=gcc
90+
;;
91+
mips64el-unknown-linux-gnuabi64)
92+
CC_FOR_BUILD=gcc
93+
;;
7694
*)
7795
CC_FOR_BUILD=clang
7896
;;

cpython-unix/build.cross.Dockerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ RUN apt-get install \
4949
gcc-aarch64-linux-gnu \
5050
gcc-arm-linux-gnueabi \
5151
gcc-arm-linux-gnueabihf \
52+
gcc-mips-linux-gnu \
53+
gcc-mips64el-linux-gnuabi64 \
54+
gcc-mipsel-linux-gnu \
5255
libc6-dev-arm64-cross \
5356
libc6-dev-armel-cross \
54-
libc6-dev-armhf-cross
57+
libc6-dev-armhf-cross \
58+
libc6-dev-mips-cross \
59+
libc6-dev-mips64el-cross \
60+
libc6-dev-mipsel-cross

cpython-unix/build.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ def add_target_env(env, build_platform, target_triple, build_env):
100100
env["CC"] = "arm-linux-gnueabi-gcc"
101101
elif target_triple == "armv7-unknown-linux-gnueabihf":
102102
env["CC"] = "arm-linux-gnueabihf-gcc"
103+
elif target_triple == "mips-unknown-linux-gnu":
104+
env["CC"] = "mips-linux-gnu-gcc"
105+
elif target_triple == "mipsel-unknown-linux-gnu":
106+
env["CC"] = "mipsel-linux-gnu-gcc"
107+
elif target_triple == "mips64el-unknown-linux-gnuabi64":
108+
env["CC"] = "mips64el-linux-gnuabi64-gcc"
103109
else:
104110
raise Exception("unhandled target triple: %s" % target_triple)
105111

@@ -120,6 +126,12 @@ def add_target_env(env, build_platform, target_triple, build_env):
120126
env["TARGET_TRIPLE"] = "armv7-unknown-linux-gnueabi"
121127
elif target_triple == "armv7-unknown-linux-gnueabihf":
122128
env["TARGET_TRIPLE"] = "armv7-unknown-linux-gnueabihf"
129+
elif target_triple == "mips-unknown-linux-gnu":
130+
env["TARGET_TRIPLE"] = "mips-unknown-linux-gnu"
131+
elif target_triple == "mipsel-unknown-linux-gnu":
132+
env["TARGET_TRIPLE"] = "mipsel-unknown-linux-gnu"
133+
elif target_triple == "mips64el-unknown-linux-gnuabi64":
134+
env["TARGET_TRIPLE"] = "mips64el-unknown-linux-gnuabi64"
123135
elif target_triple in ("x86_64-unknown-linux-gnu", "x86_64-unknown-linux-musl"):
124136
env["TARGET_TRIPLE"] = "x86_64-unknown-linux-gnu"
125137
elif target_triple == "i686-unknown-linux-gnu":
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Setup.dist doesn't have entries for all modules. This file defines
2+
# what's missing. The content here is reconstructed from logic in
3+
# setup.py and what was observed to execute in a normal build via setup.py.
4+
# We should audit this every time we upgrade CPython.
5+
6+
_bz2 _bz2module.c -lbz2
7+
_crypt _cryptmodule.c -lcrypt
8+
_ctypes _ctypes/_ctypes.c _ctypes/callbacks.c _ctypes/callproc.c _ctypes/stgdict.c _ctypes/cfield.c -I/tools/deps/include -L/tools/deps/lib -lffi -ldl
9+
_ctypes_test _ctypes/_ctypes_test.c -lm
10+
_curses _cursesmodule.c -DHAVE_NCURSESW=1 -I/tools/deps/include/ncursesw -L/tools/deps/lib -lncursesw
11+
_curses_panel _curses_panel.c -DHAVE_NCURSESW=1 -I/tools/deps/include/ncursesw -L/tools/deps/lib -lpanelw -lncursesw
12+
_dbm _dbmmodule.c -DHAVE_BERKDB_H -DDB_DBM_HSEARCH -I/tools/deps/include -L/tools/deps/lib -ldb
13+
_decimal _decimal/_decimal.c _decimal/libmpdec/basearith.c _decimal/libmpdec/constants.c _decimal/libmpdec/context.c _decimal/libmpdec/convolute.c _decimal/libmpdec/crt.c _decimal/libmpdec/difradix2.c _decimal/libmpdec/fnt.c _decimal/libmpdec/fourstep.c _decimal/libmpdec/io.c _decimal/libmpdec/mpalloc.c _decimal/libmpdec/mpdecimal.c _decimal/libmpdec/numbertheory.c _decimal/libmpdec/sixstep.c _decimal/libmpdec/transpose.c -DCONFIG_32=1 -DANSI=1 -IModules/_decimal/libmpdec
14+
_elementtree _elementtree.c -DHAVE_EXPAT_CONFIG_H=1 -DXML_POOR_ENTROPY=1 -DUSE_PYEXPAT_CAPI -IModules/expat
15+
_gdbm _gdbmmodule.c -DHAVE_NDBM_H -I/tools/deps/include -L/tools/deps/lib -lgdbm
16+
_hashlib _hashopenssl.c -I/tools/deps/include -L/tools/deps/lib -lssl -lcrypto
17+
_json _json.c
18+
_lsprof _lsprof.c rotatingtree.c
19+
_lzma _lzmamodule.c -I/tools/deps/include -L/tools/deps/lib -llzma
20+
# TODO check setup.py logic for semaphore.c and possibly fix missing
21+
# dependency.
22+
_multiprocessing _multiprocessing/multiprocessing.c _multiprocessing/semaphore.c
23+
_opcode _opcode.c
24+
_posixshmem _multiprocessing/posixshmem.c -IModules/_multiprocessing -lrt
25+
_queue _queuemodule.c
26+
_sqlite3 _sqlite/cache.c _sqlite/connection.c _sqlite/cursor.c _sqlite/microprotocols.c _sqlite/module.c _sqlite/prepare_protocol.c _sqlite/row.c _sqlite/statement.c _sqlite/util.c -I/tools/deps/include -IModules/_sqlite -DMODULE_NAME=\"sqlite3\" -DSQLITE_OMIT_LOAD_EXTENSION=1 -L/tools/deps/lib -lsqlite3
27+
_ssl _ssl.c -I/tools/deps/include -lssl -lcrypto
28+
_testbuffer _testbuffer.c
29+
_testimportmultiple _testimportmultiple.c
30+
_testinternalcapi _testinternalcapi.c -DPy_BUILD_CORE_MODULE
31+
_testmultiphase _testmultiphase.c
32+
_tkinter _tkinter.c tkappinit.c -DWITH_APPINIT -I/tools/deps/include/X11 -L/tools/deps/lib -ltcl8.6 -ltk8.6 -lX11 -lxcb -lXau
33+
_uuid _uuidmodule.c -I/tools/deps/include/uuid -luuid
34+
_xxsubinterpreters _xxsubinterpretersmodule.c
35+
_xxtestfuzz _xxtestfuzz/_xxtestfuzz.c _xxtestfuzz/fuzzer.c
36+
ossaudiodev ossaudiodev.c
37+
pyexpat pyexpat.c expat/xmlparse.c expat/xmlrole.c expat/xmltok.c -DHAVE_EXPAT_CONFIG_H=1 -DXML_POOR_ENTROPY=1 -DUSE_PYEXPAT_CAPI -IModules/expat
38+
# readline variant needs to come first because libreadline is in /tools/deps and is
39+
# picked up by build. We /could/ make libedit first. But since we employ a hack to
40+
# coerce use of libedit on Linux, it seems prudent for the build system to pick
41+
# up readline.
42+
readline VARIANT=readline readline.c -I/tools/deps/include -I/tools/deps/include/ncursesw -L/tools/deps/lib -lreadline -lncursesw
43+
readline VARIANT=libedit readline-libedit.c -DUSE_LIBEDIT=1 -I/tools/deps/libedit/include -I/tools/deps/libedit/include/ncursesw -L/tools/deps/libedit/lib -ledit -lncursesw
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Setup.dist doesn't have entries for all modules. This file defines
2+
# what's missing. The content here is reconstructed from logic in
3+
# setup.py and what was observed to execute in a normal build via setup.py.
4+
# We should audit this every time we upgrade CPython.
5+
6+
_bz2 _bz2module.c -lbz2
7+
_crypt _cryptmodule.c -lcrypt
8+
_ctypes _ctypes/_ctypes.c _ctypes/callbacks.c _ctypes/callproc.c _ctypes/stgdict.c _ctypes/cfield.c -I/tools/deps/include -L/tools/deps/lib -lffi -ldl
9+
_ctypes_test _ctypes/_ctypes_test.c -lm
10+
_curses _cursesmodule.c -DHAVE_NCURSESW=1 -I/tools/deps/include/ncursesw -L/tools/deps/lib -lncursesw
11+
_curses_panel _curses_panel.c -DHAVE_NCURSESW=1 -I/tools/deps/include/ncursesw -L/tools/deps/lib -lpanelw -lncursesw
12+
_dbm _dbmmodule.c -DHAVE_BERKDB_H -DDB_DBM_HSEARCH -I/tools/deps/include -L/tools/deps/lib -ldb
13+
_decimal _decimal/_decimal.c _decimal/libmpdec/basearith.c _decimal/libmpdec/constants.c _decimal/libmpdec/context.c _decimal/libmpdec/convolute.c _decimal/libmpdec/crt.c _decimal/libmpdec/difradix2.c _decimal/libmpdec/fnt.c _decimal/libmpdec/fourstep.c _decimal/libmpdec/io.c _decimal/libmpdec/mpalloc.c _decimal/libmpdec/mpdecimal.c _decimal/libmpdec/numbertheory.c _decimal/libmpdec/sixstep.c _decimal/libmpdec/transpose.c -DCONFIG_32=1 -DANSI=1 -IModules/_decimal/libmpdec
14+
_elementtree _elementtree.c -DHAVE_EXPAT_CONFIG_H=1 -DXML_POOR_ENTROPY=1 -DUSE_PYEXPAT_CAPI -IModules/expat
15+
_gdbm _gdbmmodule.c -DHAVE_NDBM_H -I/tools/deps/include -L/tools/deps/lib -lgdbm
16+
_hashlib _hashopenssl.c -I/tools/deps/include -L/tools/deps/lib -lssl -lcrypto
17+
_json _json.c
18+
_lsprof _lsprof.c rotatingtree.c
19+
_lzma _lzmamodule.c -I/tools/deps/include -L/tools/deps/lib -llzma
20+
# TODO check setup.py logic for semaphore.c and possibly fix missing
21+
# dependency.
22+
_multiprocessing _multiprocessing/multiprocessing.c _multiprocessing/semaphore.c
23+
_opcode _opcode.c
24+
_posixshmem _multiprocessing/posixshmem.c -IModules/_multiprocessing -lrt
25+
_queue _queuemodule.c
26+
_sqlite3 _sqlite/cache.c _sqlite/connection.c _sqlite/cursor.c _sqlite/microprotocols.c _sqlite/module.c _sqlite/prepare_protocol.c _sqlite/row.c _sqlite/statement.c _sqlite/util.c -I/tools/deps/include -IModules/_sqlite -DMODULE_NAME=\"sqlite3\" -DSQLITE_OMIT_LOAD_EXTENSION=1 -L/tools/deps/lib -lsqlite3
27+
_ssl _ssl.c -I/tools/deps/include -lssl -lcrypto
28+
_testbuffer _testbuffer.c
29+
_testimportmultiple _testimportmultiple.c
30+
_testinternalcapi _testinternalcapi.c -DPy_BUILD_CORE_MODULE
31+
_testmultiphase _testmultiphase.c
32+
_tkinter _tkinter.c tkappinit.c -DWITH_APPINIT -I/tools/deps/include/X11 -L/tools/deps/lib -ltcl8.6 -ltk8.6 -lX11 -lxcb -lXau
33+
_uuid _uuidmodule.c -I/tools/deps/include/uuid -luuid
34+
_xxsubinterpreters _xxsubinterpretersmodule.c
35+
_xxtestfuzz _xxtestfuzz/_xxtestfuzz.c _xxtestfuzz/fuzzer.c
36+
ossaudiodev ossaudiodev.c
37+
pyexpat pyexpat.c expat/xmlparse.c expat/xmlrole.c expat/xmltok.c -DHAVE_EXPAT_CONFIG_H=1 -DXML_POOR_ENTROPY=1 -DUSE_PYEXPAT_CAPI -IModules/expat
38+
# readline variant needs to come first because libreadline is in /tools/deps and is
39+
# picked up by build. We /could/ make libedit first. But since we employ a hack to
40+
# coerce use of libedit on Linux, it seems prudent for the build system to pick
41+
# up readline.
42+
readline VARIANT=readline readline.c -I/tools/deps/include -I/tools/deps/include/ncursesw -L/tools/deps/lib -lreadline -lncursesw
43+
readline VARIANT=libedit readline-libedit.c -DUSE_LIBEDIT=1 -I/tools/deps/libedit/include -I/tools/deps/libedit/include/ncursesw -L/tools/deps/libedit/lib -ledit -lncursesw

cpython-unix/targets.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,58 @@ i686-unknown-linux-gnu:
163163
- zlib
164164
openssl_target: linux-x86-clang
165165

166+
mips-unknown-linux-gnu:
167+
host_platforms:
168+
- linux
169+
docker_image_suffix: .cross
170+
needs:
171+
- bdb
172+
- binutils
173+
- bzip2
174+
- gdbm
175+
- libedit
176+
- libffi
177+
- libX11
178+
- libXau
179+
- libxcb
180+
- ncurses
181+
- readline
182+
- sqlite
183+
- tcl
184+
- tk
185+
- tix
186+
- uuid
187+
- xorgproto
188+
- xz
189+
- zlib
190+
openssl_target: linux-mips32
191+
192+
mipsel-unknown-linux-gnu:
193+
host_platforms:
194+
- linux
195+
docker_image_suffix: .cross
196+
needs:
197+
- bdb
198+
- binutils
199+
- bzip2
200+
- gdbm
201+
- libedit
202+
- libffi
203+
- libX11
204+
- libXau
205+
- libxcb
206+
- ncurses
207+
- readline
208+
- sqlite
209+
- tcl
210+
- tk
211+
- tix
212+
- uuid
213+
- xorgproto
214+
- xz
215+
- zlib
216+
openssl_target: linux-mips32
217+
166218
thumb7k-apple-watchos:
167219
host_platforms:
168220
- darwin

src/main.rs

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ const RECOGNIZED_TRIPLES: &[&str] = &[
3030
"arm64-apple-tvos",
3131
"i686-pc-windows-msvc",
3232
"i686-unknown-linux-gnu",
33+
"mips-unknown-linux-gnu",
34+
"mipsel-unknown-linux-gnu",
35+
"mips64el-unknown-linux-gnuabi64",
3336
"thumbv7k-apple-watchos",
3437
"x86_64-apple-darwin",
3538
"x86_64-apple-ios",
@@ -130,6 +133,18 @@ static GLIBC_MAX_VERSION_BY_TRIPLE: Lazy<HashMap<&'static str, version_compare::
130133
"i686-unknown-linux-gnu",
131134
version_compare::Version::from("2.17").unwrap(),
132135
);
136+
versions.insert(
137+
"mips-unknown-linux-gnu",
138+
version_compare::Version::from("2.17").unwrap(),
139+
);
140+
versions.insert(
141+
"mipsel-unknown-linux-gnu",
142+
version_compare::Version::from("2.17").unwrap(),
143+
);
144+
versions.insert(
145+
"mips64el-unknown-linux-gnuabi64",
146+
version_compare::Version::from("2.17").unwrap(),
147+
);
133148
versions.insert(
134149
"x86_64-unknown-linux-gnu",
135150
version_compare::Version::from("2.17").unwrap(),
@@ -155,6 +170,9 @@ static ELF_ALLOWED_LIBRARIES_BY_TRIPLE: Lazy<HashMap<&'static str, Vec<&'static
155170
vec!["ld-linux-armhf.so.3", "libgcc_s.so.1"],
156171
),
157172
("i686-unknown-linux-gnu", vec!["ld-linux-x86-64.so.2"]),
173+
("mips-unknown-linux-gnu", vec!["ld.so.1"]),
174+
("mipsel-unknown-linux-gnu", vec!["ld.so.1"]),
175+
("mips64el-unknown-linux-gnuabi64", vec![]),
158176
("x86_64-unknown-linux-gnu", vec!["ld-linux-x86-64.so.2"]),
159177
]
160178
.iter()
@@ -312,6 +330,9 @@ static PLATFORM_TAG_BY_TRIPLE: Lazy<HashMap<&'static str, &'static str>> = Lazy:
312330
("armv7-unknown-linux-gnueabihf", "linux-arm"),
313331
("i686-pc-windows-msvc", "win32"),
314332
("i686-unknown-linux-gnu", "linux-i686"),
333+
("mips-unknown-linux-gnu", "linux-mips"),
334+
("mipsel-unknown-linux-gnu", "linux-mipsel"),
335+
("mips64el-unknown-linux-gnuabi64", "todo"),
315336
("x86_64-apple-darwin", "macosx-10.9-x86_64"),
316337
("x86_64-apple-ios", "iOS-x86_64"),
317338
("x86_64-pc-windows-msvc", "win-amd64"),
@@ -346,6 +367,9 @@ fn validate_elf(
346367
"armv7-unknown-linux-gnueabi" => goblin::elf::header::EM_ARM,
347368
"armv7-unknown-linux-gnueabihf" => goblin::elf::header::EM_ARM,
348369
"i686-unknown-linux-gnu" => goblin::elf::header::EM_386,
370+
"mips-unknown-linux-gnu" => goblin::elf::header::EM_MIPS,
371+
"mipsel-unknown-linux-gnu" => goblin::elf::header::EM_MIPS,
372+
"mips64el-unknown-linux-gnuabi64" => 0,
349373
"x86_64-unknown-linux-gnu" => goblin::elf::header::EM_X86_64,
350374
"x86_64-unknown-linux-musl" => goblin::elf::header::EM_X86_64,
351375
_ => panic!("unhandled target triple: {}", target_triple),
@@ -375,24 +399,27 @@ fn validate_elf(
375399
.get(target_triple)
376400
.expect("max glibc version not defined for target triple");
377401

378-
let mut undefined_symbols = tugger_binary_analysis::find_undefined_elf_symbols(&bytes, elf);
379-
undefined_symbols.sort();
380-
381-
for symbol in undefined_symbols {
382-
if let Some(version) = &symbol.version {
383-
let parts: Vec<&str> = version.splitn(2, '_').collect();
384-
385-
if parts.len() == 2 {
386-
if parts[0] == "GLIBC" {
387-
let v =
388-
version_compare::Version::from(parts[1]).expect("unable to parse version");
389-
390-
if &v > wanted_glibc_max_version {
391-
errors.push(format!(
392-
"{} references too new glibc symbol {:?}",
393-
path.display(),
394-
symbol
395-
))
402+
// functionality doesn't yet support mips.
403+
if !target_triple.starts_with("mips") {
404+
let mut undefined_symbols = tugger_binary_analysis::find_undefined_elf_symbols(&bytes, elf);
405+
undefined_symbols.sort();
406+
407+
for symbol in undefined_symbols {
408+
if let Some(version) = &symbol.version {
409+
let parts: Vec<&str> = version.splitn(2, '_').collect();
410+
411+
if parts.len() == 2 {
412+
if parts[0] == "GLIBC" {
413+
let v = version_compare::Version::from(parts[1])
414+
.expect("unable to parse version");
415+
416+
if &v > wanted_glibc_max_version {
417+
errors.push(format!(
418+
"{} references too new glibc symbol {:?}",
419+
path.display(),
420+
symbol
421+
))
422+
}
396423
}
397424
}
398425
}

0 commit comments

Comments
 (0)