Bug 34210 - ffs builtin calls undefined __ffshi2
Summary: ffs builtin calls undefined __ffshi2
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 35508 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-11-23 19:38 UTC by Shaun Jackman
Modified: 2014-02-16 13:14 UTC (History)
6 users (show)

See Also:
Host:
Target: avr
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-11-23 22:39:04


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Shaun Jackman 2007-11-23 19:38:21 UTC
ffs((uint8_t)x) and ffs((uint16_t)x) generate a call to __ffshi2, but this function does not exist in libgcc.a, giving the error
undefined reference to `__ffshi2'.

Test case:

int main(int argc)
{
	return ffs(argc);
}
Comment 1 Shaun Jackman 2007-11-23 20:01:33 UTC
It's worth noting that __ffsi2 generates terrible code on the AVR: a 194 byte function. avr-libc also provides ffs (16-bit, not 32-bit as in __ffssi2) which is written in assembler and 24 bytes long. As a workaround, you can force the use of avr-libc's ffs by providing the -fno-builtin-ffs.

Cheers,
Shaun
Comment 2 Richard Biener 2007-11-23 22:39:04 UTC
Confirmed.  libgcc2.c doesn't have a ffs implementation for targets with 2
byte integers.
Comment 3 Rask Ingemann Lambertsen 2007-12-21 22:20:05 UTC
You want something like this in libgcc/config/avr/t-avr to get the 16-bit versions:

# Extra 16-bit integer functions.
intfuncs16 = _absvXX2 _addvXX3 _subvXX3 _mulvXX3 _negvXX2 _ffsXX2 _clzXX2 \
	     _ctzXX2 _popcountXX2
hiintfuncs16 = $(subst XX,hi,$(intfuncs16))
siintfuncs16 = $(subst XX,si,$(intfuncs16))

iter-items := $(hiintfuncs16)
iter-labels := $(siintfuncs16)
iter-sizes := $(patsubst %,2,$(siintfuncs16)) $(patsubst %,2,$(hiintfuncs16))

include $(srcdir)/empty.mk $(patsubst %,$(srcdir)/siditi-object.mk,$(iter-items))

libgcc-objects += $(patsubst %,%$(objext),$(hiintfuncs16))
ifeq ($(enable_shared),yes)
libgcc-s-objects += $(patsubst %,%_s$(objext),$(hiintfuncs16))
endif
Comment 4 Paulo Marques 2008-01-20 03:41:12 UTC
gcc.c-torture/execute/ffs-1.c and gcc.c-torture/execute/ffs-2.c also fail with this message. The test case gcc.c-torture/execute/builtin-bitops-1.c shows some more similar errors:

builtin-bitops-1.c:(.text+0x6b4): undefined reference to `__popcounthi2'
builtin-bitops-1.c:(.text+0x6ee): undefined reference to `__parityhi2'
builtin-bitops-1.c:(.text+0x183e): undefined reference to `__clzhi2'

I tried to add the suggested libgcc/config/avr/t-avr. It didn't work, and I don't know enough of gcc internals to understand what is going on.
Comment 5 Andy Hutchinson 2008-03-23 00:24:03 UTC
Patch posted:

http://gcc.gnu.org/ml/gcc-patches/2008-03/msg01341.html
Comment 6 Eric Weddington 2008-03-23 03:04:22 UTC
*** Bug 35508 has been marked as a duplicate of this bug. ***
Comment 7 Andy Hutchinson 2008-04-07 23:16:23 UTC
Subject: Bug 34210

Author: hutchinsonandy
Date: Mon Apr  7 23:15:35 2008
New Revision: 133993

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=133993
Log:
PR target/34210 PR target/35508 * config.host (avr-*-*): Add avr cpu_type and avr tmake_file. * config/t-avr: New file. Build 16bit libgcc functions.

Added:
    trunk/libgcc/config/avr/
    trunk/libgcc/config/avr/t-avr
Modified:
    trunk/libgcc/ChangeLog
    trunk/libgcc/config.host

Comment 8 Eric Weddington 2008-04-08 15:14:21 UTC
Commit from Andy fixes the bug.
Comment 9 Jackie Rosen 2014-02-16 13:14:59 UTC Comment hidden (spam)