[cfe-users] bug? pragma section and optimization, initialized static variable

Helmut via cfe-users cfe-users at lists.llvm.org
Sun Dec 5 11:29:11 PST 2021


Hello,

 

I'm compiling for arm with and without optimization and get different
sections for the initialized static variable myvar.

 

Unexpected section (wrong):

clang -std=c99 --target=thumbv7em-unknown-none-eabihf -g3 -O1 -gdwarf-2
-gstrict-dwarf -fdebug-macro -c main.c

 

llvm-objdump.exe .\main.o -t

-          shows that the static initialized variable myvar is in section
.bss instead of section .data.myvar as expected:

-          00000004 l     O .bss   00000001 myvar

 

Correct (expected) section without optimization (level 0):

clang -std=c99 --target=thumbv7em-unknown-none-eabihf -g3 -O0 -gdwarf-2
-gstrict-dwarf -fdebug-macro -c main.c

 

llvm-objdump.exe .\main.o -t

-          shows that the static initialized variable myvar is in section
.data.myvar instead of section .data as expected:

-          00000000 l     O .data_myvar    00000004 myvar

 

 

My example code:

 

Main.c

 

typedef enum

{

    myinit = 0x1,

    myidle = 0x2,

    mybusy = 0x3

} myenumvar;

 

int startcond;    // -> .bss

 

# pragma clang section data=".data_myvar"

static myenumvar myvar = myinit;

# pragma clang section data=""

 

int main(void)

{

  startcond = 1;

  if(1 == startcond)

  {

                if(myinit == myvar)

                {

                  myvar = mybusy;

                }

startcond = 0;

  }

  while(1);

  return 0;

}

 

 

I wonder if this is a bug or am I missing some other option flags?

 

Best regards,

Helmut

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20211205/f6d2a62d/attachment.html>


More information about the cfe-users mailing list