Clang buildworld failure due to multiple definitions of __isnanf

From: Eric McCorkle <eric_at_shadowsun.net>
Date: Sun, 26 Jun 2011 22:32:02 -0400
I've both seen reports and experienced make buildworld with clang 
failing in usr.bin/xlint/lint1 (really, make kernel-toolchain is what 
fails), because lint1 is statically linked, and there is a definition of 
__isnanf in both libc and libm.  GCC, on the other hand, builds just fine.

The file tree.c in usr.bin/xlint/lint1 calls both isnan and finite from 
math.h.  After some investigation, I figured out what's going on. 
math.h includes a macro version of isnan, which expands out to an 
expression that calls isnan, __isnanl, and __isnanf.  GCC seems to treat 
all of these as builtin functions, and implements them with its code 
generator, rather than generating calls.  Clang, on the other hand, does 
not, which leaves calls to __isnanf in the resulting object file, which 
will result in multiple definitions at link time.

There are several possible solutions.  The workaround I used is to add 
-Wl,--allow-multiple-definition to LDADD in the makefile for xlint.


A better solution, I think, is to modify math.h with something like this:

#ifdef __clang__
#define isnan(n) __builtin_isnan(n)
...
#endif

(It might be a good idea to add these kinds of definitions for all of 
clang's builtins, actually.)


Anyway, I hope this helps someone.


PS. Sorry I don't have build logs, assembler output, etc.  My FreeBSD 
machine's wireless card isn't supported (yet).

-- 
Eric McCorkle
Computer Science Ph.D Student,
University of Massachusetts
Research Intern, IBM Research
Received on Mon Jun 27 2011 - 00:32:05 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:15 UTC