Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 4 Jan 2017 21:55:51 +0200
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        Derrick McKee <derrick.mckee@gmail.com>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: Using non-standard libc
Message-ID:  <20170104195551.GA2533@kib.kiev.ua>
In-Reply-To: <CAJoBWHyG8mugoJWKzqyJYHd6faHuWA1FFYimhJ-tLf-gLLwuZg@mail.gmail.com>
References:  <CAJoBWHxmgo00FjRftxE5RpCe3%2B1jgr%2BiU_m2rufBAz9yWab7nw@mail.gmail.com> <CAJoBWHyG8mugoJWKzqyJYHd6faHuWA1FFYimhJ-tLf-gLLwuZg@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Jan 04, 2017 at 06:05:03PM +0000, Derrick McKee wrote:
> Hi,
> 
> I am conducting research into memory safety, and I have developed a custom
> LLVM pass.  I have successfully built libc using my pass.  However, when I
> try to compile a helloworld program using my built libc, I get a whole
> bunch of undefined reference errors:
> 
> /path/to/custom/clang -static -nostdlib -L/usr/src/lib/libc -lc
> -I/usr/src/include hello.c
> 
> /usr/bin/ld: warning: cannot find entry symbol _start; defaulting to
> 0000000000400160
> /usr/src/lib/libc/libc.a(getenv.o): In function `__clean_env':
> /usr/src/lib/libc/stdlib/getenv.c:(.text+0x168): undefined reference to
> `environ'
> /usr/src/lib/libc/stdlib/getenv.c:(.text+0x171): undefined reference to
> `environ'
> /usr/src/lib/libc/libc.a(getenv.o): In function `getenv':
> /usr/src/lib/libc/stdlib/getenv.c:(.text+0x1f6): undefined reference to
> `environ'
> /usr/src/lib/libc/libc.a(getenv.o): In function `__merge_environ':
> /usr/src/lib/libc/stdlib/getenv.c:(.text+0x42d): undefined reference to
> `environ'
> /usr/src/lib/libc/stdlib/getenv.c:(.text+0x459): undefined reference to
> `environ'
> /usr/src/lib/libc/libc.a(getenv.o):/usr/src/lib/libc/stdlib/getenv.c:(.text+0x524):
> more undefined references to `environ' follow
> /usr/src/lib/libc/libc.a(getprogname.o): In function `getprogname':
> /usr/src/lib/libc/gen/getprogname.c:(.text+0x7): undefined reference to
> `__progname'
> /usr/src/lib/libc/libc.a(auxv.o): In function `init_aux_vector_once':
> /usr/src/lib/libc/gen/auxv.c:(.text+0x27): undefined reference to `environ'
> /usr/src/lib/libc/libc.a(exec.o): In function `execl':
> /usr/src/lib/libc/gen/exec.c:(.text+0x154): undefined reference to `environ'
> /usr/src/lib/libc/libc.a(exec.o): In function `execlp':
> /usr/src/lib/libc/gen/exec.c:(.text+0x484): undefined reference to `environ'
> /usr/src/lib/libc/libc.a(exec.o): In function `execvp':
> /usr/src/lib/libc/gen/exec.c:(.text+0x4e3): undefined reference to `environ'
> /usr/src/lib/libc/libc.a(exec.o): In function `execv':
> /usr/src/lib/libc/gen/exec.c:(.text+0x537): undefined reference to `environ'
> /usr/src/lib/libc/libc.a(exec.o):/usr/src/lib/libc/gen/exec.c:(.text+0x5b7):
> more undefined references to `environ' follow
> clang-4.0: error: linker command failed with exit code 1 (use -v to see
> invocation)
> 
> Any idea of what I am missing?  Thanks.

You are missing the so-called crt files which ensure that the resulting
binary follows ABI etc.  Easier way for you to see what is going on is
to compile trivial program in the verbose cc driver mode:
	cc -v -o hello hello.c
You will see what are the actual tools invocation, and in particular,
how the actual linking is performed. Then you could replace system libc
reference with your own lib by invoking ld manually.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20170104195551.GA2533>