Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-fno-fortran-main not working on macOS #1221

Open
meow464 opened this issue Feb 8, 2022 · 2 comments
Open

-fno-fortran-main not working on macOS #1221

meow464 opened this issue Feb 8, 2022 · 2 comments

Comments

@meow464
Copy link

meow464 commented Feb 8, 2022

I came across this problem while compiling OpenBLAS on macOS.
Calling flang with -fno-fortran-main does nothing, by using -v you can see that ld still receives -lflangmain. To trigger an error you can use -all_load.

This command line can be used to reproduce without building OpenBLAS:

flang -v -fno-fortran-main -all_load -dynamiclib -L/usr/local/lib /usr/local/lib/libpgmath.a -o libdummy_pgmath.dylib

The error:

clang version 10.0.1 (https://github.com/flang-compiler/classic-flang-llvm-project.git 4a566ddfa4157ed1a24920ab7673ccc01c46fd99)
Target: x86_64-apple-darwin21.3.0
Thread model: posix
InstalledDir: /usr/local/bin
 "/usr/bin/ld" -demangle -lto_library /usr/local/stow/flang/lib/libLTO.dylib -dynamic -dylib -arch x86_64 -all_load -platform_version macos 10.17.0 12.1 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -o libdummy_pgmath.dylib -L/usr/local/lib /usr/local/lib/libpgmath.a -lflangmain -lflang -lflangrti -lpgmath -lompstub -lm -lpthread -lSystem
Undefined symbols for architecture x86_64:
  "_MAIN_", referenced from:
      _main in libflangmain.a(flangmain.c.o)
ld: symbol(s) not found for architecture x86_64
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)

Any tips as to why or where -fno-fortran-main is being ignored are appreciated.

EDIT: Please let me know if this bug happens on other platforms. -all_load is a very apple flag.
EDIT2: -lflangmain is still added to the linker command line but the error can't be triggered because -all_load isn't available.

@kiranchandramohan
Copy link
Collaborator

Thanks for reporting this issue. I think there is a bug in the code and currently, it requires the two flags (-fno-fortran-main and -Mnomain) to be present to not have main. Please test this.
https://github.com/flang-compiler/classic-flang-llvm-project/blob/f645e319607d5d8c8eabfb0c7dcefa544f6bbcf9/clang/lib/Driver/ToolChains/CommonArgs.cpp#L124

The fix is to change the above code to something like the following,

&& !(Args.hasArg(options::OPT_Mnomain) ||
            Args.hasArg(options::OPT_no_fortran_main)));

@meow464
Copy link
Author

meow464 commented Feb 10, 2022

@kiranchandramohan I can build for macOS with those changes 👍
EDIT: I tested it on branch release_100

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants