Skip to content

Commit

Permalink
cctools: try to use clang in as
Browse files Browse the repository at this point in the history
The clang integrated assembler is way more up-to-date than the ancient
pre-GPLv3 version of gas that is the alternative. The latter doesn't
know about newer instructions such as AVX. The as(1) shipped with
recent Xcode versions will just run clang behind the scenes under most
circumstances for this reason.

Our cctools can't actually depend on clang because that would create a
circular dependency. So we'll try to run the clang corresponding to the
LLVM being used by cctools, and if that isn't present, try the system
clang in /usr/bin if we're on an OS version that has a clang with a
working integrated assembler. (The ancient gas is still used as a final
fallback.)

Fixes: https://trac.macports.org/ticket/37846
  • Loading branch information
jmroot authored and cjones051073 committed Jan 28, 2019
1 parent 57f499f commit 7aa2ff6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 13 deletions.
13 changes: 12 additions & 1 deletion devel/cctools/Portfile
Expand Up @@ -6,6 +6,7 @@ name cctools
# Xcode 10.0
version 921
set ld64_version 409.12
revision 1
categories devel
platforms darwin
maintainers {jeremyhu @jeremyhu} openmaintainer
Expand Down Expand Up @@ -37,7 +38,7 @@ patchfiles cctools-829-lto.patch \
PR-12400897.patch \
cctools-862-prunetrie.patch \
cctools-921-noavx512.patch \
not-clang.patch
as-try-clang.patch

if {${os.major} < 11} {
patchfiles-append snowleopard-strnlen.patch
Expand Down Expand Up @@ -139,8 +140,18 @@ post-patch {
reinplace "s:\"llvm-objdump\":\"llvm-objdump-mp-${llvm_version}\":" ${worksrcpath}/otool/main.c
reinplace "s:\"llvm-mc\":\"llvm-mc-mp-${llvm_version}\":" ${worksrcpath}/as/driver.c
reinplace "s:@@LLVM_LIBDIR@@:${prefix}/libexec/llvm-${llvm_version}/lib:" ${worksrcpath}/libstuff/lto.c
reinplace "s:__MP_CLANG_NAME__:clang-mp-${llvm_version}:" ${worksrcpath}/as/driver.c
}

if {${os.major} >= 11} {
set try_system_clang 1
} else {
# clang's integrated assembler may not work well on 10.6 and doesn't
# exist on older OS versions.
set try_system_clang 0
}
reinplace "s:__TRY_SYSTEM_CLANG__:${try_system_clang}:" ${worksrcpath}/as/driver.c

foreach file [glob ${worksrcpath}/{*/,}Makefile] {
reinplace "s:/usr/local:@PREFIX@:g" ${file}
reinplace "s:/usr:@PREFIX@:g" ${file}
Expand Down
34 changes: 34 additions & 0 deletions devel/cctools/files/as-try-clang.patch
@@ -0,0 +1,34 @@
--- as/driver.c.orig 2018-09-19 08:01:56.000000000 +1000
+++ as/driver.c 2019-01-25 01:35:21.000000000 +1100
@@ -295,11 +295,18 @@ char **envp)
arch_flag.cputype == CPU_TYPE_ARM64 ||
arch_flag.cputype == CPU_TYPE_ARM64_32 ||
arch_flag.cputype == CPU_TYPE_ARM)){
- as = makestr(prefix, CLANG, NULL);
- if(access(as, F_OK) != 0){
- printf("%s: assembler (%s) not installed\n", progname, as);
- exit(1);
- }
+ as = makestr(prefix, "__MP_CLANG_NAME__", NULL);
+ if(access(as, F_OK) != 0){
+#if __TRY_SYSTEM_CLANG__
+ as = "/usr/bin/clang";
+ if(access(as, F_OK) != 0){
+ as = NULL;
+ }
+#else
+ as = NULL;
+#endif
+ }
+ if (as != NULL) {
new_argv = allocate((argc + 8) * sizeof(char *));
new_argv[0] = as;
j = 1;
@@ -360,6 +367,7 @@ char **envp)
exit(0);
else
exit(1);
+ } /* as != NULL */
}

/*
12 changes: 0 additions & 12 deletions devel/cctools/files/not-clang.patch

This file was deleted.

0 comments on commit 7aa2ff6

Please sign in to comment.