UASM icon indicating copy to clipboard operation
UASM copied to clipboard

Cannot build the latest UASM on macOS

Open anta40 opened this issue 3 years ago • 12 comments

I'm on macOS Big Sur, and have some C/C++ compilers installed:

  • gcc (a.ka clang 12) via Apple Command Line Tools
  • gcc-11 and clang 12 via Homebrew

After pulling the latest code from git, none of them can build UASM:

make -f ClangOSX64.mak 
gcc -D __UNIX__ -c -IH -D __UNIX__ -DNDEBUG -O2 -ansi -funsigned-char -fwritable-strings -o GccUnixR/dbgcv.o dbgcv.c
In file included from dbgcv.c:13:
H/memalloc.h:49:10: warning: 'alloca' macro redefined [-Wmacro-redefined]
        #define alloca(x)  __builtin_alloca(x)
                ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/alloca.h:39:9: note: previous definition is here
#define alloca(size)    __alloca(size)
        ^
In file included from dbgcv.c:14:
In file included from H/parser.h:59:
H/instruct.h:1241:10: warning: '/*' within block comment [-Wcomment]
/* #if 0 /* v2.09: added, inactive ( not supported by ML64 v8,9,10 ) */
         ^
dbgcv.c:20:10: fatal error: 'direct.h' file not found
#include <direct.h>
         ^~~~~~~~~~

So I did some adjustments on dbgcv.c:

  • Replaced <direct.h> will <unistd.h>
  • Added #define _MAX_PATH 4096
  • Replaced _getcwd with getcwd

So far, the error count is reduced into 4. I still have no idea how to solve the first 2:

dbgcv.c:1572:16: error: use of undeclared identifier '_pgmptr'
                len = strlen(_pgmptr) + 1;
                             ^
dbgcv.c:1573:17: error: use of undeclared identifier '_pgmptr'
                s = strcpy(s, _pgmptr) + len;

Seems like _pgmptr is Windows-specific.

And the last 2 are casting errors:

dbgcv.c:1582:41: error: 'char *' and 'uint_8 *' (aka 'unsigned char *') are not pointers to compatible types
                EnvBlock->reclen = (unsigned short)(s - cv.ps - 2);
                                                    ~ ^ ~~~~~
dbgcv.c:1583:9: warning: assigning to 'uint_8 *' (aka 'unsigned char *') from 'char *' converts between pointers to integer types with different sign
      [-Wpointer-sign]
                cv.ps = s;
                      ^ ~
dbgcv.c:1587:28: error: 'char *' and 'uint_8 *' (aka 'unsigned char *') are not pointers to compatible types
                cv.section->length += (s - start);

anta40 avatar May 15 '21 16:05 anta40

You may want to have a look at the changes in https://github.com/Terraspace/UASM/pull/146 and test those on your system.

justdan96 avatar Jun 10 '21 14:06 justdan96

Sorry for the late very reply. As I usual, pulled the latest code git, and applied the changes mentioned in #146. Now I'm facing different error messages:

assemble.c:1180:3: error: implicit declaration of function 'AddSimdTypes' [-Werror,-Wimplicit-function-declaration] AddSimdTypes(); ^ assemble.c:1205:30: warning: using the result of an assignment as a condition without parentheses [-Wparentheses] if ( Token_Count = Tokenize( LineStoreCurr->line, 0, ModuleInfo.tokenarray, TOK_DEFAULT ) ) ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ assemble.c:1205:30: note: place parentheses around the assignment to silence this warning if ( Token_Count = Tokenize( LineStoreCurr->line, 0, ModuleInfo.tokenarray, TOK_DEFAULT ) ) ^ ( ) assemble.c:1205:30: note: use '==' to turn this assignment into an equality comparison if ( Token_Count = Tokenize( LineStoreCurr->line, 0, ModuleInfo.tokenarray, TOK_DEFAULT ) ) ^ == assemble.c:1279:5: error: implicit declaration of function 'strupr' [-Werror,-Wimplicit-function-declaration] _strupr( ModuleInfo.name ); ^

anta40 avatar Nov 16 '21 15:11 anta40

Do you want to try the steps from this Dockerfile I made? https://github.com/justdan96/7zip_static/blob/main/Dockerfile#L13

justdan96 avatar Nov 16 '21 16:11 justdan96

Do you want to try the steps from this Dockerfile I made? https://github.com/justdan96/7zip_static/blob/main/Dockerfile#L13

I followed your steps On MacOS, seems like there's no built-in strupr(), so I took this simple implementation and put that in assemble.c

Now 1 error left:

assemble.c:1191:3: error: implicit declaration of function 'AddSimdTypes' [-Werror,-Wimplicit-function-declaration] AddSimdTypes();

anta40 avatar Dec 08 '21 01:12 anta40

I've added most of the fixes from the open pull requests plus a few extra ones to fix building on Linux. Maybe that also helps you to build on Mac: https://github.com/darealshinji/UASM

You should also disable all "-Werror" flags.

darealshinji avatar Dec 17 '21 11:12 darealshinji

Try some pull requests with your changes, maybe something will move with compiling in Linux.

teoberi avatar Dec 21 '21 09:12 teoberi

Try some pull requests with your changes, maybe something will move with compiling in Linux.

All the important fixes are already present as PRs, the rest is just silencing compiler warnings.

darealshinji avatar Dec 21 '21 12:12 darealshinji

Yes I follow the development of UASM, many want to help but nothing concrete is seen.

teoberi avatar Dec 21 '21 12:12 teoberi

I've added most of the fixes from the open pull requests plus a few extra ones to fix building on Linux. Maybe that also helps you to build on Mac: https://github.com/darealshinji/UASM

You should also disable all "-Werror" flags.

Now I'm on Debian. Running make, I got this:

cc Release/main.o Release/apiemu.o Release/orgfixup.o Release/assemble.o Release/assume.o Release/atofloat.o Release/backptch.o Release/bin.o Release/branch.o Release/cmdline.o Release/codegen.o Release/codegenv2.o Release/coff.o Release/condasm.o Release/context.o Release/cpumodel.o Release/data.o Release/dbgcv.o Release/directiv.o Release/elf.o Release/end.o Release/equate.o Release/errmsg.o Release/expans.o Release/expreval.o Release/extern.o Release/fastpass.o Release/fixup.o Release/fpfixup.o Release/hll.o Release/input.o Release/invoke.o Release/label.o Release/linnum.o Release/listing.o Release/loop.o Release/lqueue.o Release/ltype.o Release/macho64.o Release/macro.o Release/macrolib.o Release/mangle.o Release/memalloc.o Release/msgtext.o Release/omf.o Release/omffixup.o Release/omfint.o Release/option.o Release/parser.o Release/posndir.o Release/preproc.o Release/proc.o Release/queue.o Release/reswords.o Release/safeseh.o Release/segment.o Release/simd.o Release/simsegm.o Release/string.o Release/symbols.o Release/tbyte.o Release/pseudoFilter.o Release/tokenize.o Release/types.o  -s -o Release/uasm -Wl,-Map,Release/uasm.map
/usr/bin/ld: Release/orgfixup.o:(.bss+0x8): multiple definition of `MODULEARCH'; Release/main.o:(.bss+0x0): first defined here
/usr/bin/ld: Release/orgfixup.o:(.bss+0x9): multiple definition of `evexflag'; Release/main.o:(.bss+0x1): first defined here
/usr/bin/ld: Release/orgfixup.o:(.bss+0xa): multiple definition of `evex'; Release/main.o:(.bss+0x2): first defined here
/usr/bin/ld: Release/orgfixup.o:(.bss+0xb): multiple definition of `broadflags'; Release/main.o:(.bss+0x3): first defined here
/usr/bin/ld: Release/orgfixup.o:(.bss+0xc): multiple definition of `decoflags'; Release/main.o:(.bss+0x4): first defined here
/usr/bin/ld: Release/assemble.o:(.bss+0x1328): multiple definition of `MODULEARCH'; Release/main.o:(.bss+0x0): first defined here
...
...
...
/usr/bin/ld: Release/types.o:(.bss+0xa): multiple definition of `evex'; Release/main.o:(.bss+0x2): first defined here
/usr/bin/ld: Release/types.o:(.bss+0xb): multiple definition of `broadflags'; Release/main.o:(.bss+0x3): first defined here
/usr/bin/ld: Release/types.o:(.bss+0xc): multiple definition of `decoflags'; Release/main.o:(.bss+0x4): first defined here
collect2: error: ld returned 1 exit status
make: *** [Makefile:47: Release/uasm] Error 1


anta40 avatar Jan 08 '22 01:01 anta40

@anta40 Strange, I cannot confirm this on Ubuntu using gcc version 9.3.0. Make uses "cc" as compiler, are you sure that this is "gcc" on your system? Are you using the latest revision of the "gcc-fixes" branch? It says the symbol "MODULEARCH" was previously defined in main.o, but in main.c there's only one instance of this symbol and it's commented out, so that doesn't make sense (the other symbols don't even appear in main.c).

Can you try to delete the "Release" directory and run it again with "CC=gcc make -f Makefile"?

darealshinji avatar Jan 29 '22 12:01 darealshinji

When using v2.55, sed -i -e 's/-ansi/-Wno-error=implicit-function-declaration/' UASM-2.55/ClangOSX64.mak worked.

I published https://github.com/cielavenir/homebrew-ciel/blob/master/uasm.rb .

cielavenir avatar Apr 07 '22 02:04 cielavenir

sed -i -e 's/-ansi/-Wno-error=implicit-function-declaration/' UASM-2.55/ClangOSX64.mak

I just tried this using UASM 2.55 (not modified at all), and uasm built succesfully. Interestingly, it doesn't work with the very latest version on git, though.

dbgcv.c:20:10: fatal error: 'direct.h' file not found #include <direct.h>

anta40 avatar Apr 09 '22 15:04 anta40