tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] x86_64, musl: generation of mixed C/C++ fails: undefi


From: Michael Matz
Subject: Re: [Tinycc-devel] x86_64, musl: generation of mixed C/C++ fails: undefined reference to `__va_start'
Date: Thu, 3 Jan 2019 18:03:49 +0100 (CET)
User-agent: Alpine 2.21 (LSU 202 2017-01-01)

Hello,

On Thu, 3 Jan 2019, Steffen Nurpmeso wrote:

Regardless of whether i use the AlpineLinux default tcc package,
or my version with the little path-resistancy patch, i cannot
create a binary from several C files which become compiled with
tcc -static and linked to an -ar chive, and some C++ files:

 ...
 clang -Dsu_USECASE_SU -I../../src -I../../include -Wall -pedantic -o .main.o 
-c .main.cc
 tcc -Dsu_USECASE_SU -I../../src -I../../include -static -g -O1 -Wall -pedantic 
-o avopt.o -c avopt.c
 ...
 tcc -ar .clib.a avopt.o core-code.o core-errors.o cs-alloc.o cs-ctype.o 
cs-dict.o cs-find.o cs-misc.o cs-toolbox.o cs-tools.o icodec-dec.o icodec-enc.o 
mem-alloc.o mem-bag.o mem-tools.o prime.o utf.o
 clang  -o .main cxx-core.o .main.o .clib.a
 /usr/bin/ld: .clib.a(core-code.o): in function `su_log_write':
 /home/steffen/src/nail.git/src/su/core-code.c:233: undefined reference to 
`__va_start'

The reason is of course that this symbol resides in
/usr/lib/tcc/libtcc1.a, but that is unknown to the linker.
That makes me feel quite dumb, i would not know nothing but
-static in order to address that myself (except for -ar checking
unreferenced symbols for this name, i have never looked into ar(1)
but would not think it goes that far)?
Well, you have to add the TCC support library into the link process. 
Either by using TCC as linker instead of clang or by explicitely listing 
it.
That's not different from other compilers, e.g. when compiled by GCC you 
need to link with libgcc.a (or libgcc_s.so), either by using gcc as link 
editor or by listing it explicitely.  I.e. compilers always come with a 
support library that implements whatever code is relied upon by their 
implementation (e.g. for GCC that could be functions for dealing with 
decimal float numbers), and you need to include those libraries when 
linking object files produced by those compilers.  Usually that's done by 
using the respective compiler as link editor which automatically adds the 
support library.  Obviously that won't work if you use multiple compilers: 
you can only choose one as the link editor (you chose clang) and hence 
have to list the support library of the other one explicitely (libtcc1.a 
for your case).
You seem to be under the impression that -ar somehow could deal with this: 
it can't.  ar does nothing more than essentially packing all object files 
you listed into one .a file.  In particular no symbol resolution or 
linking steps are involved, and so the reference to __va_start is left 
untouched.  In this case even listing libtcc.a wouldn't help as ar 
leaves other archives alone.  You would have to unpack libtcc.a and 
include its individual object files in the tcc -ar command.  (But then you 
can just as well just mention that library in the link editing step 
later).
I hope this clarifies the problem a bit.  In short: you have to list 
libtcc.a explicitely.

Ciao,
Michael.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]