[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
replying!
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.
--
Mats
>
> Thanks,
> Shilpa
>
> On Fri, Nov 18, 2016 at 9:39 PM, mats petersson <mats at planetcatfish.com>
> wrote:
>
>> 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:
>> https://github.com/Leporacanthicus/lacsap/blob/master/binary.cpp#L126
>>
>> --
>> Mats
>>
>> On 18 November 2016 at 11:20, Shilpa B via llvm-dev <
>> llvm-dev at lists.llvm.org> wrote:
>>
>>> Hi,
>>>
>>> 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?
>>>
>>>
>>> Thanks
>>> -Shilpa
>>>
>>> _______________________________________________
>>> LLVM Developers mailing list
>>> llvm-dev at lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161118/0600d0d1/attachment-0001.html>
More information about the llvm-dev
mailing list