Got "Malformed Mach-o file" on Mac Catilina when make firmware

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
User avatar
lolomarx
Posts: 15
Joined: Wed Jan 08, 2020 4:03 am

Got "Malformed Mach-o file" on Mac Catilina when make firmware

Post by lolomarx » Fri Jan 10, 2020 5:47 am

Had set up ~/edp-idf and ~/esp/xtensa-esp32-elf

On ~/.bashrc :

Code: Select all

export PATH=$HOME/esp/xtensa-esp32-elf/bin:$PATH
export IDF_PATH=~/esp/esp-idf
Then go to ports/esp32 and perform "make V=1", but got "Malformed Mach-o file" error as below :

Code: Select all

MPY modules/flashbdev.py
mkdir -p build/frozen_mpy/
../../mpy-cross/mpy-cross -o build/frozen_mpy/flashbdev.mpy -s flashbdev.py  modules/flashbdev.py
make: ../../mpy-cross/mpy-cross: Malformed Mach-o file
make: *** [build/frozen_mpy/flashbdev.mpy] Error 1

User avatar
jimmo
Posts: 1421
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Got "Malformed Mach-o file" on Mac Catilina when make firmware

Post by jimmo » Fri Jan 10, 2020 5:57 am

Can you try running (from the top-level micropython directory):

Code: Select all

cd mpy-cross
make clean
make
./mpy-cross --help

User avatar
lolomarx
Posts: 15
Joined: Wed Jan 08, 2020 4:03 am

Re: Got "Malformed Mach-o file" on Mac Catilina when make firmware

Post by lolomarx » Fri Jan 10, 2020 6:43 am

Code: Select all

./mpy-cross --help
mpy-cross can't work

Code: Select all

make clean
Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.
rm -f mpy-cross
rm -f mpy-cross.map
rm -rf build 

Code: Select all

CC gccollect.c
LINK mpy-cross
BFD: mpy-cross: unknown load command 0x32
   text	   data	    bss	    dec	    hex	filename
 130999	  13512	    860	 145371	  237db	mpy-cross
HanYu:mpy-cross hanyu$ ./mpy-cross --help
Killed: 9


User avatar
jimmo
Posts: 1421
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Got "Malformed Mach-o file" on Mac Catilina when make firmware

Post by jimmo » Fri Jan 10, 2020 11:38 am

Can you do a "make clean" again in mpy-cross, then "make V=1" and include the last few lines of output (anything that shows a compiler invocation line. I'm curious to know what compiler it's using.

Then maybe the output of running the complier with --version. It'll likely be clang (or gcc). But it almost sounds like it's using something else?

If you're feeling adventurous, can you try making a really small hello world C program and try compiling and running that?

User avatar
lolomarx
Posts: 15
Joined: Wed Jan 08, 2020 4:03 am

Re: Got "Malformed Mach-o file" on Mac Catilina when make firmware

Post by lolomarx » Sat Jan 11, 2020 12:39 am

Here are the "HelloWorld" testing result

Code: Select all

vim HelloWorld.cpp
$ clang++ -o HelloWorld HelloWorld.cpp
$ ./HelloWorld
Hello world!
$ clang++ --version
Apple clang version 11.0.0 (clang-1100.0.33.8)
Target: x86_64-apple-darwin19.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

User avatar
jimmo
Posts: 1421
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Got "Malformed Mach-o file" on Mac Catilina when make firmware

Post by jimmo » Sat Jan 11, 2020 12:43 am

MicroPython is C, so it won't be using clang++.

Using make V=1 you should be able to get the exact compiler and linker binary that MicroPython is using.

User avatar
lolomarx
Posts: 15
Joined: Wed Jan 08, 2020 4:03 am

Re: Got "Malformed Mach-o file" on Mac Catilina when make firmware

Post by lolomarx » Sat Jan 11, 2020 2:32 am

Code: Select all

clang --version
Apple clang version 11.0.0 (clang-1100.0.33.8)
Target: x86_64-apple-darwin19.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Code: Select all

$ make V=1
mkdir -p build/genhdr
python3 ../py/makeversionhdr.py build/genhdr/mpversion.h
Generating build/genhdr/mpversion.h
GEN build/genhdr/qstr.i.last
clang -E -DNO_QSTR -DN_X64 -DN_X86 -DN_THUMB -DN_ARM -DN_XTENSA -Ibuild/tmp -I. -I.. -Ibuild -Wall -Werror -Wpointer-arith -Wuninitialized -std=gnu99 -DFFCONF_H=\"lib/oofatfs/ffconf.h\" -Os   -fdata-sections -ffunction-sections -fno-asynchronous-unwind-tables -w ../py/mpstate.c ../py/malloc.c ../py/gc.c ../py/qstr.c ../py/vstr.c ../py/mpprint.c ../py/unicode.c ../py/mpz.c ../py/reader.c ../py/lexer.c ../py/parse.c ../py/scope.c ../py/compile.c ../py/emitcommon.c ../py/emitbc.c ../py/asmbase.c ../py/asmx64.c ../py/asmx86.c ../py/asmthumb.c ../py/emitinlinethumb.c ../py/asmarm.c ../py/asmxtensa.c ../py/emitinlinextensa.c ../py/formatfloat.c ../py/parsenumbase.c ../py/parsenum.c ../py/emitglue.c ../py/persistentcode.c ../py/runtime.c ../py/runtime_utils.c ../py/scheduler.c ../py/nativeglue.c ../py/stackctrl.c ../py/argcheck.c ../py/warning.c ../py/map.c ../py/obj.c ../py/objarray.c ../py/objattrtuple.c ../py/objbool.c ../py/objboundmeth.c ../py/objcell.c ../py/objclosure.c ../py/objcomplex.c ../py/objdict.c ../py/objenumerate.c ../py/objexcept.c ../py/objfilter.c ../py/objfloat.c ../py/objfun.c ../py/objgenerator.c ../py/objgetitemiter.c ../py/objint.c ../py/objint_longlong.c ../py/objint_mpz.c ../py/objlist.c ../py/objmap.c ../py/objmodule.c ../py/objobject.c ../py/objpolyiter.c ../py/objproperty.c ../py/objnone.c ../py/objnamedtuple.c ../py/objrange.c ../py/objreversed.c ../py/objset.c ../py/objsingleton.c ../py/objslice.c ../py/objstr.c ../py/objstrunicode.c ../py/objstringio.c ../py/objtuple.c ../py/objtype.c ../py/objzip.c ../py/opmethods.c ../py/sequence.c ../py/stream.c ../py/binary.c ../py/builtinimport.c ../py/builtinevex.c ../py/builtinhelp.c ../py/modarray.c ../py/modbuiltins.c ../py/modcollections.c ../py/modgc.c ../py/modio.c ../py/modmath.c ../py/modcmath.c ../py/modmicropython.c ../py/modstruct.c ../py/modsys.c ../py/moduerrno.c ../py/modthread.c ../py/vm.c ../py/bc.c ../py/showbc.c ../py/repl.c ../py/smallint.c ../py/frozenmod.c ../py/../extmod/moductypes.c ../py/../extmod/modujson.c ../py/../extmod/modure.c ../py/../extmod/moduzlib.c ../py/../extmod/moduheapq.c ../py/../extmod/modutimeq.c ../py/../extmod/moduhashlib.c ../py/../extmod/modubinascii.c ../py/../extmod/virtpin.c ../py/../extmod/machine_mem.c ../py/../extmod/machine_pinbase.c ../py/../extmod/machine_signal.c ../py/../extmod/machine_pulse.c ../py/../extmod/machine_i2c.c ../py/../extmod/machine_spi.c ../py/../extmod/modussl_axtls.c ../py/../extmod/modussl_mbedtls.c ../py/../extmod/modurandom.c ../py/../extmod/moduselect.c ../py/../extmod/modwebsocket.c ../py/../extmod/modwebrepl.c ../py/../extmod/modframebuf.c ../py/../extmod/vfs.c ../py/../extmod/vfs_reader.c ../py/../extmod/vfs_fat.c ../py/../extmod/vfs_fat_diskio.c ../py/../extmod/vfs_fat_file.c ../py/../extmod/vfs_fat_misc.c ../py/../extmod/utime_mphal.c ../py/../extmod/uos_dupterm.c ../py/../lib/embed/abort_.c ../py/../lib/utils/printf.c ../py/emitnative.c >build/genhdr/qstr.i.last;

User avatar
lolomarx
Posts: 15
Joined: Wed Jan 08, 2020 4:03 am

Re: Got "Malformed Mach-o file" on Mac Catilina when make firmware

Post by lolomarx » Sat Jan 11, 2020 4:11 am

For a try. clang to build HelloWorld is ok.

Code: Select all

clang HelloWorld.c 
$ a.out
Hello World!

User avatar
jimmo
Posts: 1421
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Got "Malformed Mach-o file" on Mac Catilina when make firmware

Post by jimmo » Sat Jan 11, 2020 4:15 am

That's very strange.

I guess out of curiosity, are you able to compile and run the unix port of MicroPython

Code: Select all

cd ports/unix
make FROZEN_MANIFEST=
./micropython
(Setting frozen manifest to empty to prevent it running mpy-cross)

User avatar
lolomarx
Posts: 15
Joined: Wed Jan 08, 2020 4:03 am

Re: Got "Malformed Mach-o file" on Mac Catilina when make firmware

Post by lolomarx » Sat Jan 11, 2020 5:42 am

still can't prevent running mpy-cross:

Code: Select all

make FROZEN_MANIFEST=
Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.
Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.
MPY modules/upip_utarfile.py
make: ../../mpy-cross/mpy-cross: Malformed Mach-o file
make: *** [build/frozen_mpy/upip_utarfile.mpy] Error 1

Code: Select all

HanYu:unix hanyu$ make V=1 FROZEN_MANIFEST=
python3 ../../py/makeversionhdr.py build/genhdr/mpversion.h
/Library/Developer/CommandLineTools/usr/bin/make -C ../../mpy-cross
python3 ../py/makeversionhdr.py build/genhdr/mpversion.h
MPY modules/upip_utarfile.py
mkdir -p build/frozen_mpy/
../../mpy-cross/mpy-cross -o build/frozen_mpy/upip_utarfile.mpy -s upip_utarfile.py -mcache-lookup-bc modules/upip_utarfile.py
make: ../../mpy-cross/mpy-cross: Malformed Mach-o file
make: *** [build/frozen_mpy/upip_utarfile.mpy] Error 1

Post Reply