Fix clang AS

This commit is contained in:
Thomas Pöchtrager 2015-10-24 10:55:59 +02:00
parent 68b961c6b2
commit 029fcb835b
4 changed files with 69 additions and 17 deletions

View File

@ -21,6 +21,8 @@
/* used by error calls (exported) */
char *progname = NULL;
char *find_clang(); /* cctools-port */
int
main(
int argc,
@ -280,6 +282,10 @@ char **envp)
arch_flag.cputype == CPU_TYPE_ARM)
run_clang = 1;
#ifndef DISABLE_CLANG_AS /* cctools-port */
if(getenv("NO_CLANG_AS") != NULL) /* cctools-port */
run_clang = 0;
/*
* Use the clang as the assembler if is the default or asked to with
* the -q flag. But don't use it asked to use the system assembler
@ -290,12 +296,16 @@ char **envp)
arch_flag.cputype == CPU_TYPE_I386 ||
arch_flag.cputype == CPU_TYPE_ARM64 ||
arch_flag.cputype == CPU_TYPE_ARM)){
#if 0 /* cctools port */
as = makestr(prefix, CLANG, NULL);
if(access(as, F_OK) != 0){
#else
as = find_clang();
#endif
if(!as || access(as, F_OK) != 0){ /* cctools-port: added !as || */
printf("%s: assembler (%s) not installed\n", progname, as);
exit(1);
}
new_argv = allocate((argc + 8) * sizeof(char *));
new_argv = allocate((argc + 10) * sizeof(char *)); /* cctools-port: + 8 -> + 10 */
new_argv[0] = as;
j = 1;
/*
@ -350,12 +360,19 @@ char **envp)
/* Add -c or clang will run ld(1). */
new_argv[j] = "-c";
j++;
/* cctools-port start */
new_argv[j] = "-target";
j++;
new_argv[j] = "unknown-apple-darwin";
j++;
/* cctools-port end */
new_argv[j] = NULL;
if(execute(new_argv, verbose))
exit(0);
else
exit(1);
}
#endif /* ! DISABLE_CLANG_AS */
/*
* If this assembler exist try to run it else print an error message.

View File

@ -324,6 +324,17 @@ AC_SUBST(XAR_LIB)
fi
### Check whether we want to use clang as assembler ###
AC_ARG_ENABLE([clang-as],
AS_HELP_STRING([--disable-clang-as],
[do not use clang for assembling]),
[], [enable_clang_as=yes])
if test "x$enable_clang_as" != "xyes"; then
CFLAGS="$CFLAGS -DDISABLE_CLANG_AS"
fi
### Check endianness ###
AC_C_BIGENDIAN([AC_SUBST([ENDIAN_FLAG],[-D__BIG_ENDIAN__=1])],

View File

@ -14,7 +14,7 @@ libstuff_la_SOURCES = \
crc32.c \
dylib_roots.c \
dylib_table.c \
emulated.c \
port.c \
errors.c \
execute.c \
fatal_arch.c \

View File

@ -1,29 +1,59 @@
#ifndef __APPLE__
#include <mach/mach.h>
#include <mach/mach_error.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/mman.h>
/* #include <sys/attr.h> */
#include <errno.h>
#include <inttypes.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <sys/time.h>
#include <mach/mach.h>
#include <mach/mach_error.h>
#include <mach/mach_time.h>
#include <mach/mach_host.h>
#include <mach/host_info.h>
#include <sys/time.h>
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
#include <sys/sysctl.h>
#endif
#ifdef __OpenBSD__
#include <sys/types.h>
#include <sys/user.h>
#include <sys/stat.h>
#endif
char *find_clang()
{
char *p, *path = getenv("PATH");
char clang[MAXPATHLEN];
struct stat st;
if (!path)
return NULL;
path = strdup(path);
if (!path)
return NULL;
p = strtok(path, ":");
while (p != NULL)
{
snprintf(clang, sizeof(clang), "%s/clang", p);
if (stat(clang, &st) == 0 && access(clang, F_OK|X_OK) == 0)
return strdup(clang);
p = strtok(NULL, ":");
}
free(path);
return NULL;
}
int _NSGetExecutablePath(char *epath, unsigned int *size)
{
#if defined(__FreeBSD__) || defined(__DragonFly__)
@ -207,9 +237,6 @@ vm_size_t vm_page_size = 4096; /* hardcoded to match expectations of darwin */
#ifndef HAVE_STRMODE
#include <sys/cdefs.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
void strmode(/* mode_t */ int mode, char *p)
{
@ -339,9 +366,6 @@ void strmode(/* mode_t */ int mode, char *p)
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/types.h>
#include <string.h>
/*
* Copy src to string dst of size siz. At most siz-1 characters
* will be copied. Always NUL terminates (unless siz == 0).