Radare2: Unable Detect Clang Compiler in MacOS

Created on 2 Nov 2018  Â·  15Comments  Â·  Source: radareorg/radare2

Hi,
When building librz.a clang has an error, I didn't yet check why it's happened.

$uname -a 
Darwin xxx.local 18.2.0 Darwin Kernel Version 18.2.0: Fri Oct  5 19:41:49 PDT 2018; root:xnu-4903.221.2~2/RELEASE_X86_64 x86_64
$clang --version
Apple LLVM version 10.0.0 (clang-1000.10.44.2)
Target: x86_64-apple-darwin18.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
cp -f ../../shlr/spp//config.def.h ../../shlr/spp//config.h
/Library/Developer/CommandLineTools/usr/bin/make spp_build
make[2]: Nothing to be done for `spp_build'.
/Library/Developer/CommandLineTools/usr/bin/make all2
"gcc -dynamiclib -o libr_util.dylib -Wl,-install_name,/opt/local//lib/libr_util.dylib binheap.o mem.o unum.o str.o hex.o file.o range.o tinyrange.o prof.o cache.o sys.o buf.o w32-sys.o ubase64.o base85.o base91.o list.o flist.o mixed.o btree.o chmod.o graph.o event.o regex/regcomp.o regex/regerror.o regex/regexec.o uleb128.o sandbox.o calc.o thread.o thread_sem.o thread_lock.o thread_cond.o strpool.o bitmap.o date.o format.o pie.o print.o ctype.o seven.o slist.o randomart.o zip.o debruijn.o log.o utf8.o utf16.o utf32.o strbuf.o lib.o name.o spaces.o signal.o syscmd.o diff.o bdiff.o stack.o queue.o tree.o des.o idpool.o assert.o punycode.o pkcs7.o x509.o asn1.o astr.o json_indent.o skiplist.o r_json.o rbtree.o qrcode.o trie.o vector.o str_trim.o ascii_table.o ../../shlr/sdb/src/buffer.o ../../shlr/sdb/src/cdb.o ../../shlr/sdb/src/cdb_make.o ../../shlr/sdb/src/ht.o ../../shlr/sdb/src/sdbht.o ../../shlr/sdb/src/json.o ../../shlr/sdb/src/lock.o ../../shlr/sdb/src/ls.o ../../shlr/sdb/src/ns.o ../../shlr/sdb/src/query.o ../../shlr/sdb/src/sdb.o ../../shlr/sdb/src/base64.o ../../shlr/sdb/src/disk.o ../../shlr/sdb/src/dict.o ../../shlr/sdb/src/array.o ../../shlr/sdb/src/fmt.o ../../shlr/sdb/src/match.o ../../shlr/sdb/src/num.o ../../shlr/sdb/src/util.o ../../shlr/sdb/src/journal.o ../../shlr/spp/spp.o       -fPIC /opt/radare2/libr/../shlr/zip/librz.a -fvisibility=hidden     -lpthread  -lm -fvisibility=hidden"
ld: warning: ignoring file /opt/radare2/libr/../shlr/zip/librz.a, file was built for archive which is not the architecture being linked (x86_64): /opt/radare2/libr/../shlr/zip/librz.a
Undefined symbols for architecture x86_64:
  "_inflate", referenced from:
      _r_inflate in zip.o
     (maybe you meant: _r_inflate)
  "_inflateEnd", referenced from:
      _r_inflate in zip.o
  "_inflateInit2_", referenced from:
      _r_inflate in zip.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [libr_util.dylib] Error 1
make[1]: *** [all] Error 2
make: *** [all] Error 2
MacOS buildsystem

Most helpful comment

@SajjadPourali and @ZhangZhuoSJTU are you using binutils from brew (_Check with brew list | grep binutils_)?

I solved uninstalling it and just using binutils from Xcode (default).

All 15 comments

It seems problem is related to build script, it can not detect compiler is clang.

Final report:
 - R_CHECKS_LEVEL = 2
 - PREFIX = /usr/local
 - HAVE_LIB_GMP = 0
 - HAVE_OPENSSL = 0
 - HAVE_LIBUV = 0
 - USE_CAPSTONE = 0
 - HAVE_PTRACE = 1
 - USE_PTRACE_WRAP = 0
 - HAVE_FORK = 1
 - VERSION = 3.1.0-git
 - USE_LIB_ZIP = 0
 - USE_LIB_MAGIC = 0
 - USE_LIB_XXHASH = 0
 - DEBUGGER = 1
 - CC = gcc
 - USERCC = gcc
 - HAVE_ARC4RANDOM_UNIFORM = 1
 - HAVE_EXPLICIT_BZERO = 0
 - USEROSTYPE = darwin
 - LIBVERSION = 3.1.0-git
 - BUILD = x86_64-unknown-darwin
 - HOST = x86_64-unknown-darwin
 - TARGET = x86_64-unknown-darwin

is this r2 from git? are you using sys/install.sh ? otherwise just make a clean clone and do that. you probably have a trashed builddir, you can also git clean -xdf

On 2 Nov 2018, at 19:32, Sajjad Pourali notifications@github.com wrote:

Hi,
When building librz.a clang has an error, I didn't yet check why it's happened.

$uname -a
Darwin xxx.local 18.2.0 Darwin Kernel Version 18.2.0: Fri Oct 5 19:41:49 PDT 2018; root:xnu-4903.221.2~2/RELEASE_X86_64 x86_64
$clang --version
Apple LLVM version 10.0.0 (clang-1000.10.44.2)
Target: x86_64-apple-darwin18.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
cp -f ../../shlr/spp//config.def.h ../../shlr/spp//config.h
/Library/Developer/CommandLineTools/usr/bin/make spp_build
make[2]: Nothing to be done for `spp_build'.
/Library/Developer/CommandLineTools/usr/bin/make all2
"gcc -dynamiclib -o libr_util.dylib -Wl,-install_name,/opt/local//lib/libr_util.dylib binheap.o mem.o unum.o str.o hex.o file.o range.o tinyrange.o prof.o cache.o sys.o buf.o w32-sys.o ubase64.o base85.o base91.o list.o flist.o mixed.o btree.o chmod.o graph.o event.o regex/regcomp.o regex/regerror.o regex/regexec.o uleb128.o sandbox.o calc.o thread.o thread_sem.o thread_lock.o thread_cond.o strpool.o bitmap.o date.o format.o pie.o print.o ctype.o seven.o slist.o randomart.o zip.o debruijn.o log.o utf8.o utf16.o utf32.o strbuf.o lib.o name.o spaces.o signal.o syscmd.o diff.o bdiff.o stack.o queue.o tree.o des.o idpool.o assert.o punycode.o pkcs7.o x509.o asn1.o astr.o json_indent.o skiplist.o r_json.o rbtree.o qrcode.o trie.o vector.o str_trim.o ascii_table.o ../../shlr/sdb/src/buffer.o ../../shlr/sdb/src/cdb.o ../../shlr/sdb/src/cdb_make.o ../../shlr/sdb/src/ht.o ../../shlr/sdb/src/sdbht.o ../../shlr/sdb/src/json.o ../../shlr/sdb/src/lock.o ../../shlr/sdb/src/ls.o ../../shlr/sdb/src/ns.o ../../shlr/sdb/src/query.o ../../shlr/sdb/src/sdb.o ../../shlr/sdb/src/base64.o ../../shlr/sdb/src/disk.o ../../shlr/sdb/src/dict.o ../../shlr/sdb/src/array.o ../../shlr/sdb/src/fmt.o ../../shlr/sdb/src/match.o ../../shlr/sdb/src/num.o ../../shlr/sdb/src/util.o ../../shlr/sdb/src/journal.o ../../shlr/spp/spp.o -fPIC /opt/radare2/libr/../shlr/zip/librz.a -fvisibility=hidden -lpthread -lm -fvisibility=hidden"
ld: warning: ignoring file /opt/radare2/libr/../shlr/zip/librz.a, file was built for archive which is not the architecture being linked (x86_64): /opt/radare2/libr/../shlr/zip/librz.a
Undefined symbols for architecture x86_64:
"_inflate", referenced from:
_r_inflate in zip.o
(maybe you meant: _r_inflate)
"_inflateEnd", referenced from:
_r_inflate in zip.o
"_inflateInit2_", referenced from:
_r_inflate in zip.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: * [libr_util.dylib] Error 1
make[1]:
[all] Error 2
make: *
* [all] Error 2
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub https://github.com/radare/radare2/issues/12044, or mute the thread https://github.com/notifications/unsubscribe-auth/AA3-lmQ_qRN9hn4jssJKL-0eXUaaPxa1ks5urI-3gaJpZM4YMCrX.

Yes, I did try with make and sys/install.sh.
result of sys/install.sh:
https://asciinema.org/a/HtyFF5sGTiI5kOrormBpcNzDT

result of make command :
https://asciinema.org/a/K4BdilN5rzP97VZJb8fv0rwQN

env:

TERM_PROGRAM=iTerm.app
TERM=xterm-256color
SHELL=/bin/bash
TMPDIR=/var/folders/zw/***/T/
Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.***/Render
TERM_PROGRAM_VERSION=3.2.5
TERM_SESSION_ID=***:***
USER=***
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.***/Listeners
__CF_USER_TEXT_ENCODING=0x0:0:0
PATH=/Users/***/.cargo/bin:/Users/***/.jenv/shims:/Users/***/.rbenv/shims:/opt/local/bin:/usr/local/opt/findutils/libexec/gnubin:/Users/***/.cargo/bin:/usr/local/bin:/usr/local/sbin:/Users/***/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/Library/TeX/texbin:/opt/X11/bin:/Applications/Wireshark.app/Contents/MacOS
JENV_LOADED=1
PWD=/opt/radare2
LANG=en_US.UTF-8
ITERM_PROFILE=Default
XPC_FLAGS=0x0
RBENV_SHELL=bash
XPC_SERVICE_NAME=0
SHLVL=1
HOME=/Users/***
COLORFGBG=7;0
ITERM_SESSION_ID=***:****
LOGNAME=***
DISPLAY=/private/tmp/com.apple.launchd.***/org.macosforge.xquartz:0
COLORTERM=truecolor
_=/usr/bin/env
OLDPWD=/opt
$gcc -v
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.0 (clang-1000.10.44.2)
Target: x86_64-apple-darwin18.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
$uname -a
Darwin ***.local 18.2.0 Darwin Kernel Version 18.2.0: Fri Oct  5 19:41:49 PDT 2018; root:xnu-4903.221.2~2/RELEASE_X86_64 x86_64

Same problem here.

$ uname -a
Darwin xxx.local 18.0.0 Darwin Kernel Version 18.0.0: Wed Aug 22 20:13:40 PDT 2018; root:xnu-4903.201.2~1/RELEASE_X86_64 x86_64
$ clang --version
Apple LLVM version 10.0.0 (clang-1000.10.44.4)
Target: x86_64-apple-darwin18.0.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Error report is almost the same:

ld: warning: ignoring file XXX/radare2/libr/../shlr/zip/librz.a, file was built for archive which is not the architecture being linked (x86_64): XXX/radare2/libr/../shlr/zip/librz.a
Undefined symbols for architecture x86_64:
  "_inflate", referenced from:
      _r_inflate in zip.o
     (maybe you meant: _r_inflate)
  "_inflateEnd", referenced from:
      _r_inflate in zip.o
  "_inflateInit2_", referenced from:
      _r_inflate in zip.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [libr_util.dylib] Error 1
make[1]: *** [all] Error 2
make: *** [all] Error 2

Did you git clean -xdf. Sounds to me like you have upgraded xcode and the builddir have still object files created with the old one

I think I have done git clean -xdf, but it failed. I also cloned the repo in a new directory, same error occurred.

The real error here is in
8f1d57cd-6243-423f-93a9-6be5708d57f6

I have also seen warnings that are fixed in master.. and cant repro yet..

I have also seen warnings that are fixed in master.. and cant repro yet..

It can be fix by using libtool -static instead of ar q command.


Please check this topic too : https://stackoverflow.com/questions/52529838/gdb-8-2-cant-recognized-executable-file-on-macos-mojave-10-14#answer-52995622

@SajjadPourali A quick question. May I know which place you have edited to make clang work? I tried but failed these days. :(

I still cant reproduce this issue and i have tested in several machines and environmwnts

On 7 Nov 2018, at 17:25, izhuer notifications@github.com wrote:

@SajjadPourali A quick question. May I know which place you have edited to make clang work? I tried but failed these days. :(

—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub, or mute the thread.

I have also seen warnings that are fixed in master.. and cant repro yet..

Could you please let me know which commit fixed these warnings? This might help me debug about why building failed on my machine. Thanks a lot.

@ZhangZhuoSJTU : I did attach my changes, it's dirty fix but it works.
my changes : radare-fixed.tar.gz

sorry, I didn't create patch file, because I'm sleepy and capstone needs patch too, it take a little bit time.

@SajjadPourali and @ZhangZhuoSJTU are you using binutils from brew (_Check with brew list | grep binutils_)?

I solved uninstalling it and just using binutils from Xcode (default).

@sferrini : Thank you,I did unlink binutils and it works.
I think when I did update binutils to 2.31.1, this problem appears.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RazviAlex picture RazviAlex  Â·  4Comments

YugoCode picture YugoCode  Â·  6Comments

PaquitoRiviera picture PaquitoRiviera  Â·  7Comments

ret2libc picture ret2libc  Â·  6Comments

securitykitten picture securitykitten  Â·  4Comments