[PATCH] D14236: Unbreak build on OpenBSD

Stefan Kempf via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 3 06:19:17 PST 2015


Joerg Sonnenberger via llvm-commits wrote:
> On Mon, Nov 02, 2015 at 03:45:17PM +0000, Stefan Kempf via llvm-commits wrote:
> > sisnkemp created this revision.
> > sisnkemp added a subscriber: llvm-commits.
> > 
> > This is similar to the fix for FreeBSD in r226862. Without this patch,
> > the build aborts when linkling libLTO.so, complaining about undefined
> . references to __assert2, __cxa_atexit, etc.
> 
> Link explicitly against libc?

Tried that first: you would have to link against libc and libssp. And
then you still get undefined references to environ.

environ sits in either /usr/lib/crt0.o or /usr/lib/gcrt0.o.

But those files seem to be linkable into executables only, ld complains
when you try to pass one of them when building a shared lib. See example
below. Also, you'd have to check whether you need to link crt0 or gcrt0
in the LLVM build, depending on whether you compile with -pg.

So I suggest going with the proposed diff.

Quick example:

$ cat x.c

#include <stdio.h>

extern char *environ;

int
foo(void)
{
	puts("hi");
	return environ == (void *)0;
}

$ gcc -fPIC -Wl,-z -Wl,defs x.c -shared -o x.so

/tmp//ccT7OS1x.o: In function `foo':
x.c:(.text+0x10): undefined reference to `puts'
x.c:(.text+0x17): undefined reference to `environ'
collect2: ld returned 1 exit status

$ gcc -fPIC -Wl,-z -Wl,defs x.c -shared -o x.so /usr/lib/crt0.o

x.c:(.text+0x10): undefined reference to `puts'
/usr/bin/ld: /usr/lib/crt0.o: relocation R_X86_64_PC32 against `__progname' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: ld returned 1 exit status


More information about the llvm-commits mailing list