linux build broken on Ubuntu 12.04 x86_64

Hey all,

FYI -

We’re seeing a whole host of errors around requiring arc4random and linkage errors building llvm/clang/lldb from top of tree. This is on lldb builds with Ubuntu 12.04 x86_64, using gcc 4.8.2 and configure-based builds. This appeared to crop up sometime since Friday morning. What’s the right fix for that? Looks to be a dependency on libbsd?

Weird. Probably best to send mail to lldb@?

-eric

Ah. Weird. I’m not seeing anything. Can you paste the errors you’re seeing?

-eric

First error: head file related. Strangely, this code has been there a while, which makes me think that the HAVE_ARC4RANDOM is somehow now showing up as set whereas perhaps it didn’t used to be.

tfiala@tfiala2:~/lldb/svn/lgs/build$ make

make[1]: Entering directory `/mnt/ssd/work/svn/lgs/build/lib/Support’

llvm[1]: Compiling Process.cpp for Debug+Asserts build

In file included from /mnt/ssd/work/svn/lgs/llvm/lib/Support/Process.cpp:103:0:

/mnt/ssd/work/svn/lgs/llvm/lib/Support/Unix/Process.inc: In static member function ‘static unsigned int llvm::sys::Process::GetRandomNumber()’:

/mnt/ssd/work/svn/lgs/llvm/lib/Support/Unix/Process.inc:368:21: error: ‘arc4random’ was not declared in this scope

return arc4random();

^

/mnt/ssd/work/svn/lgs/llvm/lib/Support/Unix/Process.inc:374:1: warning: control reaches end of non-void function [-Wreturn-type]

}

^

/bin/rm: cannot remove `/mnt/ssd/work/svn/lgs/build/lib/Support/Debug+Asserts/Process.d.tmp’: No such file or directory

make[1]: *** [/mnt/ssd/work/svn/lgs/build/lib/Support/Debug+Asserts/Process.o] Error 1

make[1]: Leaving directory `/mnt/ssd/work/svn/lgs/build/lib/Support’

make: *** [all] Error 1

If I add #include <bsd/stdlib.h>, I get past that:

Index: lib/Support/Unix/Process.inc

===================================================================

— lib/Support/Unix/Process.inc (revision 200620)

+++ lib/Support/Unix/Process.inc (working copy)

@@ -38,6 +38,9 @@

#ifdef HAVE_TERMIOS_H

include <termios.h>

#endif

+#if defined(HAVE_ARC4RANDOM)

+# include <bsd/stdlib.h>

+#endif

//===----------------------------------------------------------------------===//

//=== WARNING: Implementation here must contain only generic UNIX code that

Then I start fixing up link errors like the following that now require -lbsd:

make[2]: Entering directory `/mnt/ssd/work/svn/lgs/build/utils/fpcmp’

llvm[2]: Linking Debug+Asserts executable fpcmp

/mnt/ssd/work/svn/lgs/build/Debug+Asserts/lib/libLLVMSupport.a(Process.o): In function `llvm::sys::Process::GetRandomNumber()':

/mnt/ssd/work/svn/lgs/llvm/lib/Support/Unix/Process.inc:371: undefined reference to `arc4random’

collect2: error: ld returned 1 exit status

make[2]: *** [/mnt/ssd/work/svn/lgs/build/Debug+Asserts/bin/fpcmp] Error 1

make[2]: Leaving directory `/mnt/ssd/work/svn/lgs/build/utils/fpcmp’

make[1]: *** [fpcmp/.makeall] Error 2

make[1]: Leaving directory `/mnt/ssd/work/svn/lgs/build/utils’

make: *** [all] Error 1

That’ll get resolved with something like this (don’t know how many platforms would need this fix - this should definitely bee ifdef guarded).

tfiala@tfiala2:/mnt/ssd/work/svn/lgs/llvm/utils/fpcmp$ svn diff Makefile

Index: Makefile

===================================================================

— Makefile (revision 200725)

+++ Makefile (working copy)

@@ -12,5 +12,7 @@

USEDLIBS = LLVMSupport.a

NO_INSTALL = 1

+LDFLAGS += “-lbsd”

include $(LEVEL)/Makefile.common

But this is just one of several (more below):

llvm[4]: Building Debug+Asserts Archive Library libclang.a

/mnt/ssd/work/svn/lgs/build/Debug+Asserts/lib/libLLVMSupport.a(Process.o): In function `llvm::sys::Process::GetRandomNumber()':

/mnt/ssd/work/svn/lgs/llvm/lib/Support/Unix/Process.inc:371: undefined reference to `arc4random’

collect2: error: ld returned 1 exit status

make[4]: *** [/mnt/ssd/work/svn/lgs/build/Debug+Asserts/bin/diagtool] Error 1

make[4]: Leaving directory `/mnt/ssd/work/svn/lgs/build/tools/clang/tools/diagtool’

make[3]: *** [diagtool/.makeall] Error 2

make[3]: *** Waiting for unfinished jobs…

/mnt/ssd/work/svn/lgs/build/Debug+Asserts/lib/libLLVMSupport.a(Process.o): In function `llvm::sys::Process::GetRandomNumber()':

/mnt/ssd/work/svn/lgs/llvm/lib/Support/Unix/Process.inc:371: undefined reference to `arc4random’

collect2: error: ld returned 1 exit status

make[4]: *** [/mnt/ssd/work/svn/lgs/build/Debug+Asserts/bin/clang-format] Error 1

make[4]: Leaving directory `/mnt/ssd/work/svn/lgs/build/tools/clang/tools/clang-format’

make[3]: *** [clang-format/.makeall] Error 2

/mnt/ssd/work/svn/lgs/build/Debug+Asserts/lib/libLLVMSupport.a(Process.o): In function `llvm::sys::Process::GetRandomNumber()':

/mnt/ssd/work/svn/lgs/llvm/lib/Support/Unix/Process.inc:371: undefined reference to `arc4random’

collect2: error: ld returned 1 exit status

make[4]: *** [/mnt/ssd/work/svn/lgs/build/Debug+Asserts/bin/arcmt-test] Error 1

make[4]: Leaving directory `/mnt/ssd/work/svn/lgs/build/tools/clang/tools/arcmt-test’

make[3]: *** [arcmt-test/.makeall] Error 2

/mnt/ssd/work/svn/lgs/build/Debug+Asserts/lib/libLLVMSupport.a(Process.o): In function `llvm::sys::Process::GetRandomNumber()':

/mnt/ssd/work/svn/lgs/llvm/lib/Support/Unix/Process.inc:371: undefined reference to `arc4random’

collect2: error: ld returned 1 exit status

make[4]: *** [/mnt/ssd/work/svn/lgs/build/Debug+Asserts/bin/clang-check] Error 1

make[4]: Leaving directory `/mnt/ssd/work/svn/lgs/build/tools/clang/tools/clang-check’

make[3]: *** [clang-check/.makeall] Error 2

make[4]: Leaving directory `/mnt/ssd/work/svn/lgs/build/tools/clang/tools/libclang’

make[4]: Entering directory `/mnt/ssd/work/svn/lgs/build/tools/clang/tools/c-index-test’

llvm[4]: Compiling c-index-test.c for Debug+Asserts build

llvm[4]: Linking Debug+Asserts executable c-index-test

/mnt/ssd/work/svn/lgs/build/Debug+Asserts/lib/libclang.so: undefined reference to `arc4random’

collect2: error: ld returned 1 exit status

make[4]: *** [/mnt/ssd/work/svn/lgs/build/Debug+Asserts/bin/c-index-test] Error 1

make[4]: Leaving directory `/mnt/ssd/work/svn/lgs/build/tools/clang/tools/c-index-test’

make[3]: *** [all] Error 1

/mnt/ssd/work/svn/lgs/build/Debug+Asserts/lib/libLLVMSupport.a(Process.o): In function `llvm::sys::Process::GetRandomNumber()':

/mnt/ssd/work/svn/lgs/llvm/lib/Support/Unix/Process.inc:371: undefined reference to `arc4random’

collect2: error: ld returned 1 exit status

make[4]: *** [/mnt/ssd/work/svn/lgs/build/Debug+Asserts/bin/clang] Error 1

make[4]: Leaving directory `/mnt/ssd/work/svn/lgs/build/tools/clang/tools/driver’

make[3]: *** [driver/.makeall] Error 2

We’ve got it confirmed on another machine here.

We build with gcc 4.8.2, Ubuntu 12.04 x86_64, configure-based, with the only non-Ubuntu components being the gcc and a newer libedit required by some recent changes to lldb.

Generally this has been rock solid. I don’t know if something caused the HAVE_ARC4RANDOM flag to change all of a sudden, but if it did, it happened to two machines simultaneously.

Any thoughts?

Maybe a machine change? Let’s take this off list for now and we can update when we figure it out. I can’t duplicate it.

-eric

Ok - sounds good. Thanks Eric.

Huh, I have just hit this issue today’s morning.

Maybe a machine change? Let's take this off list for now and we can update when we figure it out. I can't duplicate it.

This issue happens only if libedit-dev is installed on Ubuntu 12.04. This leads configure to false detect HAVE_ARC4RANDOM, because libedit is being tested before arc4random, and libedit.so depends on libbsd.so. This makes arc4random check succeed, even arc4random is not declared anywhere, as plain C just assumes function existence (no args returning int), then it links with -ledit which succeeds.

So I am seeing two possible solutions:

(1) either move libedit check after arc4random, so arc4random is checked without -ledit
(2) make sure arc4random check if function is actually declared, and fail instead assuming it exists and returns int

Cheers,

Thanks, Adam.

I came to the same conclusion and I just put up a patch for review to handle this a moment ago on llvm-commits.

The patch might need to be tweaked to coordinate on the variable name change that occurred due to the changed configure mechanism. I’m looking at that now.