[LLVMdev] MC ARM ELF local common variable alignment.

Eli Friedman eli.friedman at gmail.com
Wed Jul 20 10:14:40 PDT 2011


Already filed; http://llvm.org/bugs/show_bug.cgi?id=10128 .

-Eli

On Wed, Jul 20, 2011 at 10:05 AM, Jason Kim <jasonwkim at google.com> wrote:
>
> Hi,
> Can you please file a bug and Cc me directly on it?
> I'll go take a look soon.
> Thanks
> -jason
> On Wed, Jul 20, 2011 at 9:53 AM, TDYa127 <a127a127 at gmail.com> wrote:
>>
>> Hi all,
>>
>> I noticed that the static local variable(internal global in .bc) is
>> not aligned in ARM ELF(use MC(-filetype=obj)).
>> Then I found that the alignment information is lost at:
>> lib/CodeGen/AsmPrinter/AsmPrinter.cpp:316
>>    if (MAI->hasLCOMMDirective()) {
>>      // .lcomm _foo, 42
>>      OutStreamer.EmitLocalCommonSymbol(GVSym, Size);
>>      return;
>>    }
>>
>> MCStreamer::EmitLocalCommonSymbol have no parameter about alignment.
>>
>> Is this issue will cause some problem?
>>
>>
>>
>> The original c code:
>> ===========test-lcomm.c=========
>> #include <stdio.h>
>> int main(){
>>    static char a;
>>    static long long b;
>>    static long long c;
>>    scanf("%c%lld%lld",&a,&b,&c);
>>    printf("%c%lld%lld",a,b,c);
>> }
>> ================================
>>
>> I use clang, compile test-lcomm.c to bitcode:
>> $ clang test-lcomm.c -ccc-host-triple armv7-none-linux-gnueabi
>> -emit-llvm -c -o test-lcomm.bc
>>
>> bitcode:
>> ===test-lcomm.ll===
>> ; ModuleID = 'test-lcomm.c'
>> target datalayout =
>>
>> "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:64:128-a0:0:64-n32"
>> target triple = "armv7-none-linux-gnueabi"
>>
>> @main.a = internal global i8 0, align 1
>> @main.b = internal global i64 0, align 8
>> @main.c = internal global i64 0, align 8
>> @.str = private unnamed_addr constant [11 x i8] c"%c%lld%lld\00", align 1
>>
>> define i32 @main() nounwind {
>> entry:
>>  %retval = alloca i32, align 4
>>  store i32 0, i32* %retval
>>  %call = call i32 (i8*, ...)* @__isoc99_scanf(i8* getelementptr
>> inbounds ([11 x i8]* @.str, i32 0, i32 0), i8* @main.a, i64* @main.b,
>> i64* @main.c)
>>  %tmp = load i8* @main.a, align 1
>>  %conv = zext i8 %tmp to i32
>>  %tmp1 = load i64* @main.b, align 8
>>  %tmp2 = load i64* @main.c, align 8
>>  %call3 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds
>> ([11 x i8]* @.str, i32 0, i32 0), i32 %conv, i64 %tmp1, i64 %tmp2)
>>  %0 = load i32* %retval
>>  ret i32 %0
>> }
>>
>> declare i32 @__isoc99_scanf(i8*, ...)
>>
>> declare i32 @printf(i8*, ...)
>> ===================
>>
>>
>> Then, use llc to generate .o :
>> $ llc test-lcomm.bc -filetype=obj -O0 -o test-lcomm.o
>> And use readelf to print out the symbol table
>> $ readelf -s test-lcomm.o
>>
>> Symbol table '.symtab' contains 14 entries:
>>   Num:    Value  Size Type    Bind   Vis      Ndx Name
>>     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
>>     1: 00000000     0 FILE    LOCAL  DEFAULT  ABS test-lcomm.bc
>>     2: 00000000    11 OBJECT  LOCAL  DEFAULT    6 .L.str
>>     3: 00000000     1 OBJECT  LOCAL  DEFAULT    4 main.a
>>     4: 00000001     8 OBJECT  LOCAL  DEFAULT    4 main.b
>>     5: 00000009     8 OBJECT  LOCAL  DEFAULT    4 main.c
>> ...
>>
>> The variable b, c is not aligned to 8.
>>
>> (The llvm commit I used is 4c8164813c1be51f6797fda6826bdf3665f2a7d1)
>>
>>
>> Sorry for it being so long.
>>
>>
>> Thanks,
>> TDYa127
>> _______________________________________________
>> LLVM Developers mailing list
>> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>




More information about the llvm-dev mailing list