LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 7883 - [indirectbr] Clang cannot build Erlang/OTP R14A (erts-5.8)
Summary: [indirectbr] Clang cannot build Erlang/OTP R14A (erts-5.8)
Status: RESOLVED FIXED
Alias: None
Product: clang
Classification: Unclassified
Component: -New Bugs (show other bugs)
Version: 2.7
Hardware: PC Linux
: P normal
Assignee: Unassigned Clang Bugs
URL:
Keywords: compile-fail, slow-compile
Depends on:
Blocks:
 
Reported: 2010-08-14 02:05 PDT by Michael T. Richter
Modified: 2019-02-21 13:46 PST (History)
9 users (show)

See Also:
Fixed By Commit(s):


Attachments
This is the offending file. (160.85 KB, text/x-csrc)
2010-08-14 02:34 PDT, Michael T. Richter
Details
beam_emu.i.gz (80.90 KB, application/x-gzip)
2010-08-15 13:10 PDT, Pawel Worach
Details
beam_bp.i.gz (56.10 KB, application/x-gzip)
2010-08-15 13:26 PDT, Pawel Worach
Details
Bugpoint reduced bitcode for beam_emu.c (4.75 KB, application/octet-stream)
2010-10-10 03:17 PDT, Haitao Li
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michael T. Richter 2010-08-14 02:05:30 PDT
Issuing the following sequence causes compilation of the standard Erlang/OTP distribution, last tested on R14A (erts-5.8), to fail.

The precise sequence of commands to replicate this behaviour (checked on several machines) is:

CC=clang CXX=clang++ ./configure
make

The resulting build works fine until the file beam/beam_emu.c is reached.  At this point, under gcc, the file compiles in seconds while under clang there is a VERY long period of time where one core plateaus at 100% for well over a minute.  It then proceeds to spew the following error messages:

... lots of verbiage ...
... there's dozens of the warnings I've put here at the head as an example ...
beam/beam_emu.c:4938:6: warning: incompatible integer to pointer conversion passing 'Uint' (aka 'unsigned long'), expected 'void const *'
      [-pedantic]
     Goto(hcc->opcode);
     ^~~~~~~~~~~~~~~~~
beam/beam_emu.c:55:26: note: instantiated from:
#  define Goto(Rel) goto *(Rel)
                         ^~~~~~
57 diagnostics generated.
/tmp/cc-dkaevH.s: Assembler messages:
/tmp/cc-dkaevH.s:312: Error: symbol `.LBA12_process_main_' is already defined
/tmp/cc-dkaevH.s:393: Error: symbol `.LBA12_process_main_' is already defined
/tmp/cc-dkaevH.s:1644: Error: symbol `.LBA12_process_main_' is already defined
/tmp/cc-dkaevH.s:2464: Error: symbol `.LBA12_process_main_' is already defined
/tmp/cc-dkaevH.s:2554: Error: symbol `.LBA12_process_main_' is already defined
/tmp/cc-dkaevH.s:3414: Error: symbol `.LBA12_process_main_' is already defined
/tmp/cc-dkaevH.s:4235: Error: symbol `.LBA12_process_main_' is already defined
... these messages continue for a long time -- hundreds of lines ...

/tmp/cc-dkaevH.s:185467: Error: symbol `.LBA12_process_main_' is already defined
/tmp/cc-dkaevH.s:185861: Error: symbol `.LBA12_process_main_' is already defined
/tmp/cc-dkaevH.s:185952: Error: symbol `.LBA12_process_main_' is already defined
/tmp/cc-dkaevH.s:186389: Error: symbol `.LBA12_process_main_' is already defined
/tmp/cc-dkaevH.s:186868: Error: symbol `.LBA12_process_main_' is already defined
clang: error: assembler command failed with exit code 1 (use -v to see invocation)
make[3]: *** [obj/x86_64-unknown-linux-gnu/opt/smp/beam_emu.o] Error 1
make[3]: Leaving directory `/home/michael/Development/Erlang/otp_src_R14A/erts/emulator'
make[2]: *** [opt] Error 2
make[2]: Leaving directory `/home/michael/Development/Erlang/otp_src_R14A/erts/emulator'
make[1]: *** [smp] Error 2
make[1]: Leaving directory `/home/michael/Development/Erlang/otp_src_R14A/erts'
make: *** [emulator] Error 2

The Erlang/OTP distribution that fails to build can be found at http://www.erlang.org/download/otp_src_R14A.tar.gz and, from my experiences, displays the failure 100% of the time under clang.
Comment 1 Michael T. Richter 2010-08-14 02:06:49 PDT
It goes without saying that if you need me to run some builds with instrumentation, etc. I'm perfectly willing to do so.
Comment 2 Michael T. Richter 2010-08-14 02:34:48 PDT
Created attachment 5367 [details]
This is the offending file.
Comment 3 Eli Friedman 2010-08-14 15:31:03 PDT
Can you attach a preprocessed version of the offending file?
Comment 4 Pawel Worach 2010-08-15 13:09:37 PDT
I tried this on x86_64-unknown-freebsd8.1, beam_emu.c compiles and assembles fine however it takes about 5 minutes.

clang version 2.8 (trunk 111104)
GNU assembler version 2.15 [FreeBSD]

If you tried clang 2.7 you should try with trunk.

The beam.smp program also fails to link so there are more problems here:
obj/x86_64-unknown-freebsd8.1/opt/smp/erl_nif.o(.text+0x32a9): In function `load_nif_2':
/tmp/otp_src_R14A/erts/emulator/beam/erl_nif.c:1550: undefined reference to `bp_sched2ix'

time-report for beam_emu.c looks like (-O3, -O1 and above is really slow):
===-------------------------------------------------------------------------===
                      ... Pass execution timing report ...
===-------------------------------------------------------------------------===
  Total Execution Time: 346.9275 seconds (348.0264 wall clock)

   ---User Time---   --System Time--   --User+System--   ---Wall Time---  --- Name ---
  101.9335 ( 29.6%)   0.0074 (  0.3%)  101.9410 ( 29.4%)  102.2654 ( 29.4%)  Simple Register Coalescing
  83.7629 ( 24.3%)   0.0075 (  0.3%)  83.7704 ( 24.1%)  84.0212 ( 24.1%)  Simplify the CFG
  55.1255 ( 16.0%)   0.0450 (  1.7%)  55.1705 ( 15.9%)  55.3348 ( 15.9%)  Eliminate PHI nodes for register allocation
  45.1728 ( 13.1%)   0.0000 (  0.0%)  45.1728 ( 13.0%)  45.3152 ( 13.0%)  Simplify the CFG
  15.2029 (  4.4%)   0.0000 (  0.0%)  15.2029 (  4.4%)  15.2501 (  4.4%)  Simplify the CFG
  15.2023 (  4.4%)   0.0000 (  0.0%)  15.2023 (  4.4%)  15.2489 (  4.4%)  Simplify the CFG
  13.0935 (  3.8%)   0.0750 (  2.8%)  13.1685 (  3.8%)  13.2150 (  3.8%)  Linear Scan Register Allocator
Comment 5 Pawel Worach 2010-08-15 13:10:28 PDT
Created attachment 5372 [details]
beam_emu.i.gz

clang -g -O1 -fomit-frame-pointer -c beam_emu.i
Comment 6 Pawel Worach 2010-08-15 13:25:20 PDT
The undefined bp_sched2ix symbol problem looks like this:

0>root@one /tmp# nm beam_bp-clang.o | grep bp_sched2ix
1>root@one /tmp# nm beam_bp-gcc.o | grep bp_sched2ix
0000000000000030 T bp_sched2ix

-O level seems to change the symbols presence:
0>pwo@pwo-mac /tmp% clang -c beam_bp.i 
0>pwo@pwo-mac /tmp% nm beam_bp.o | grep bp_sched2ix
                 U _bp_sched2ix

0>pwo@pwo-mac /tmp% clang -O3 -c beam_bp.i
0>pwo@pwo-mac /tmp% nm beam_bp.o | grep bp_sched2ix
0>pwo@pwo-mac /tmp%

pre-processed beam_bp.c comming up...
Comment 7 Pawel Worach 2010-08-15 13:26:00 PDT
Created attachment 5373 [details]
beam_bp.i.gz
Comment 8 Chris Lattner 2010-08-17 19:09:31 PDT
FWIW, the warning is legit, add a cast to (void*) in the "Goto" macro.
Comment 9 Haitao Li 2010-10-10 03:17:05 PDT
Created attachment 5600 [details]
Bugpoint reduced bitcode for beam_emu.c

I got Erlang build by adding a few changes. Patch at: 
http://github.com/lht/otp/commit/4663872e3635d777292b4cc285420355cb9f9d95

Besides the VERY slow compilation of file beam_emu.c, the generated target beam doesn't starts correctly.

$ ./bin/erl
(no error logger present) error: "Error in process <0.1.0> with exit value: {{badfun,[<<5 bytes>>,<<21 bytes>>,<<9 bytes>>,<<3 bytes>>,<<2 bytes>>,<<5 bytes>>,<<13 bytes>>,<<2 bytes>>]},[{erlang,apply,2}]}

The debug built beam starts successfully.
$ ./bin/erl
Erlang R14B01 (erts-5.8.2) [source] [rq:1] [async-threads:0] [kernel-poll:false] [type-assertions] [debug-compiled] [lock-checking]

Eshell V5.8.2  (abort with ^G)
1>

Bugpoint reduced bitcode bugpoint-reduced-simplified.bc is attached.

*** You can reproduce the problem with: opt bugpoint-reduced-simplified.bc -globalopt -ipsccp -deadargelim -instcombine -simplifycfg -prune-eh -inline -functionattrs -argpromotion -scalarrepl -simplify-libcalls -instcombine -jump-threading -correlated-propagation -simplifycfg -instcombine -tailcallelim -simplifycfg -reassociate -loop-rotate -licm -loop-unswitch -instcombine -indvars -loop-deletion -loop-unroll -instcombine -gvn -memcpyopt -sccp -instcombine -jump-threading -correlated-propagation -dse -adce -simplifycfg -strip-dead-prototypes -deadtypeelim -globaldce -constmerge

$ clang --version
clang version 2.9 (trunk 116150)
Target: i386-pc-linux-gnu
Thread model: posix
Comment 10 Tom Care 2011-03-06 15:16:36 PST
I also get the faulty beam using clang, but I get the same thing using llvm-gcc too. gcc-4.2 seems to be the only one that can build the complete erlang install (including the hipe compiler).
Comment 11 Bill Wendling 2013-10-16 23:25:24 PDT
This no longer fails to compile on MacOSX.
Comment 12 Reid Kleckner 2019-02-21 13:46:27 PST
(In reply to Bill Wendling from comment #11)
> This no longer fails to compile on MacOSX.

Based on this comment, I think we can close this.