[LLVMdev] Linking strncpy

Eric Zimmerman ezimmerm at uiuc.edu
Wed Apr 14 20:24:01 PDT 2004


Chris,

I'm fine with using JIT, but I'm trying to understand this problem:
1. My LLVM program does not produce correct results
2. Using llvm-dis, I disassemble the bytecode to C
3. I recompile using GCC and the program _works correctly_.

The only odd thing is when I recompile with GCC, I see these messages:

pal3.c:195: warning: conflicting types for built-in function `strcmp'
pal3.c:200: warning: conflicting types for built-in function `memcpy'
pal3.c:202: warning: conflicting types for built-in function `strncpy'

The lines referenced are:
int strcmp(signed char *, signed char *);
signed char *memcpy(signed char *, signed char *, unsigned );
signed char *strncpy(signed char *, signed char *, unsigned );

Do you have any insight into what's happening?  Thanks,
-Eric

----- Forwarded message from Chris Lattner <sabre at nondot.org> -----

Date: Wed, 14 Apr 2004 19:25:45 -0500 (CDT)
From: Chris Lattner <sabre at nondot.org>
To: llvmdev at cs.uiuc.edu
Subject: Re: [LLVMdev] Linking strncpy
Reply-To: llvmdev at cs.uiuc.edu

On Wed, 14 Apr 2004, Eric Zimmerman wrote:
> I'm working on a CS326 compiler project, and I'm having some problems
> using string functions.  Some LLVM programs produced are either
> aborting or giving incorrect results; however, if I disassemble the
> LLVM bytecode and recompile with GCC, everything works fine.
>
> I encountered the following error when running lli with
> '-force-interpreter' option:
> "Tried to execute an unknown external function: sbyte * (sbyte
> *, sbyte *, uint) * strncpy"

This is one of the "features" of the interpreter: it only supports
external functions that it "knows" about.  Why not use the JIT, without
-force-interpreter?  Are you on a machine that we don't support?  If so,
you can either add support for strncpy (to
lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp) or use the C
backend.

-Chris


> Strncpy is used as part of my compiler's run-time library, and it was
> compiled with the C-frontend for LLVM.  Looking at the assembly, the
> function is declared at the top of the file;
>
> declare sbyte* %strncpy(sbyte*,sbyte*,uint) ;; __builtin_strncpy
>
> And it is called like this:
> 	%tmp.12 = call sbyte* (sbyte*, sbyte*, uint)* %strncpy(sbyte*
> %tmp.15, sbyte* %tmp.23, uint %tmp.27)
>
> What am I forgetting to do?  What is the right way to link to the
> string functions?  Thanks,
>
> -Eric Zimmerman
>




More information about the llvm-dev mailing list