pret / agbcc

C compiler
104 stars 75 forks source link

build script fails on newer version of MacOS #38

Open tustin2121 opened 3 years ago

tustin2121 commented 3 years ago

On MacOS Catalina and above, builds of the agbcc project always fail. Several people have reported this problem in various places in the discord server, myself being one of them.

Symptoms generally include the build.sh script failing partway through with the following error:

gcc -MT toplev.o -MMD -MP -MF .d/toplev.Td -g -std=gnu11 -DOLD_COMPILER -I/usr/local/opt/qt/include -I. -I. -c toplev.c
toplev.c:1048:11: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
    error(message);
          ^~~~~~~
toplev.c:1048:11: note: treat the string as an argument to avoid this
    error(message);
          ^
          "%s", 
toplev.c:2382:13: error: implicit declaration of function 'unlink' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
            unlink(aux_info_file_name);
            ^
toplev.c:2390:13: error: implicit declaration of function 'unlink' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
            unlink(offset_info_file_name);
            ^
toplev.c:3486:14: warning: 'sizeof (indep_options)' will return the size of the pointer, not the array itself [-Wsizeof-pointer-div]
    for (k = NUM_ELEM(indep_options); k--; )
             ^~~~~~~~~~~~~~~~~~~~~~~
toplev.c:728:34: note: expanded from macro 'NUM_ELEM'
#define NUM_ELEM(a)  (sizeof (a) / sizeof ((a)[0]))
                      ~~~~~~~~~~ ^
toplev.c:3441:32: note: pointer 'indep_options' declared here
    lang_independent_options * indep_options;
                               ^
2 warnings and 2 errors generated.
make: *** [toplev.o] Error 1

and/or attempt to call make on one of pret's projects failing with the following error:

clang: error: unknown argument: '-Map'

The problem may lie in the fact that mac uses clang for its implementation of gcc, but simply installing gcc via homebrew does not fix the problem. Manually bypassing clang (by setting CC to a specific version installed via homebrew like gcc-9 or gcc-10) seems to function as a workaround in the meantime.

Ideally, the build script should deal with the potential problem and either fix or give instructions for fixing the problem. Failing that, some sort of documentation on how to set up agbcc on new MacOS would help greatly.

luckytyphlosion commented 3 years ago

unlink is supposed to be included in <unistd.h>. Looking through the commit history, <unistd.h> was never included in the first place, and I'm not sure why the gcc developers at the time didn't include it. Try including <unistd.h> and see if that helps.

luckytyphlosion commented 3 years ago

I tried installing Clang on WSL1 (both Clang 10 and Clang 12), and I didn't seem to get the error. Clang simply treated it as a warning. The only way I could get it to error is by explicitly setting -Werror-implicit-function-declaration. I don't know why it's erroring for some users. Perhaps it has something to do with the default CFLAGS?

luckytyphlosion commented 3 years ago

From: https://developer.apple.com/documentation/xcode-release-notes/xcode-12-release-notes

Clang now reports an error when you use a function without an explicit declaration when building C or Objective-C code for macOS (-Werror=implicit-function-declaration flag is on). This additional error detection unifies Clang’s behavior for iOS/tvOS and macOS 64-bit targets for this diagnostic. (49917738)

luckytyphlosion commented 3 years ago

(Should have posted in the above message <:masuda:544196054740893706>) So the solution is either to add -Wno-implicit-function-declaration, or to actually fix the implicit function declarations. Vestaiden in Discord tried the immediate solution of #include <unistd.h> but that only caused further issues.

Manurocker95 commented 3 years ago

Facing same issues on Macbook Pro M1 (Apple Silicon) with Big Sur 11.2.1, any updates?

LucaBGt commented 3 years ago

MacBook Pro with Big Sur 11.2.2 here, same issue.

pizza2004 commented 3 years ago

https://github.com/pizza2004/agbcc/commit/870e98780af6df3076d65d4c2af5251f0e4f5de2

This commit makes it build, but it catches somewhere else and I cannot figure out why.

Manurocker95 commented 3 years ago

pizza2004@870e987

This commit makes it build, but it catches somewhere else and I cannot figure out why.

Not working for me:

image
pizza2004 commented 3 years ago

I never encountered anything like that and I'm not really equipped to tell you why it's happening either. Apparently downloading gmake and gcc will make it function like on other systems and it'll no longer be a problem, so I guess that's the solution now.

Manurocker95 commented 3 years ago

I never encountered anything like that and I'm not really equipped to tell you why it's happening either. Apparently downloading gmake and gcc will make it function like on other systems and it'll no longer be a problem, so I guess that's the solution now.

Any tutorial to how to configure them on macos?

Because I'm supposed to have GNU Make 3.81 and the latest gcc-arm-none-eabi

pizza2004 commented 3 years ago

I'm not sure, I just know that's what luckytyphlosion was talking about on the Discord.

Manurocker95 commented 3 years ago

I'm not sure, I just know that's what luckytyphlosion was talking about on the Discord.

His repo doesn't allow issues and Pret hasn't updated this issue so I guess I'm stuck :/

luckytyphlosion commented 3 years ago

I am lazy and busy, ask in 3-4 weeks when I'll have more time :trollface:

Manurocker95 commented 3 years ago

I am lazy and busy, ask in 3-4 weeks when I'll have more time :trollface:

what about now (?)

luckytyphlosion commented 3 years ago

Join the Discord (check any one of the decompilation readmes) and I can help resolve the macOS problem.

TGFbSMAD commented 2 years ago

Segfault seems to be specific to Macs with M1 Tried to ./build.sh on three differents macs running Big Sur 11.4, had no success with the M1 one (segfault 11)

rawr51919 commented 2 years ago

Fixed in #39