[llvm-dev] Linking LLVM IR with standard library
mats petersson via llvm-dev
llvm-dev at lists.llvm.org
Fri Nov 18 10:06:39 PST 2016
Do reply to ALL recipients (in particular to the mailing list) when
On 18 November 2016 at 17:27, Shilpa B <shilpabvb at gmail.com> wrote:
> Hi Mats,
> Thanks for the reply and the link. I am attaching the sample file that I
> had used to test.
> It is an LLVM IR file and I modified it to include rand function to
> generate random numbers and used the command
> clang print.ll -std=c++11 -Wl,-rpath,/usr/include -o print.o
> to generate the executable file. However, when I execute print.o it shows
> the random numbers generated as zero.
Nope, rand is (most likely) returning correct values you are printing
floating point values from integer values, and that quite often results in
zero being printed - depending on the architecture, register vs. memory
used for varargs, etc.
@.str = private unnamed_addr constant [4 x i8] c"%f\09\00", align 1
%callr = call i32 @rand()
store i32 %callr, i32* %arrayidx5, align 8
%val = load i32, i32* %arrayidx5, align 8
%call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8],
[4 x i8]* @.str, i32 0, i32 0), i32 %val)
change %f to %d, and it lists a bunch of seemingly random numbers, at least
on my machine.
> On Fri, Nov 18, 2016 at 9:39 PM, mats petersson <mats at planetcatfish.com>
>> Without reproducible steps, it's hard to give meaningful advice. In my
>> experience, linking using `clang` (or `gcc`) will work.
>> My compiler does that around in this function:
>> On 18 November 2016 at 11:20, Shilpa B via llvm-dev <
>> llvm-dev at lists.llvm.org> wrote:
>>> I have a LLVM IR file generated for a different source language (Not C).
>>> I have added a rand() function in it to generate random numbers.
>>> I compiled the .ll file to .o using clang. However, when I execute the
>>> .o file all generated numbers are zeros.
>>> How should I link the .ll file with the standard library for the clang
>>> to generate the random numbers?
>>> LLVM Developers mailing list
>>> llvm-dev at lists.llvm.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the llvm-dev