I am working with clang llvm and trying to have the pragma defines in my output code. The .section is not getting in the output of the code. I am trying to generate the output for the below test.c code.
#include <stddef.h> // test.c file
#pragma clang section bss="myBSS" data="myData" rodata="myRodata" relro="myRelro" text=".myText"
int var1;
int var2;
int var3 = 7;
const int var4 = 10;
void notmain(void);
void notmain(void) {}
int main(void)
{
notmain();
}
I cross-complile using clang llvm using the following command for i686 target.
$ clang --target=i686-pc-windows-msvc -S -o test_s.s test.c
I get the below output in the assembly
.text
.def @feat.00;
.scl 3;
.type 0;
.endef
.globl @feat.00
.set @feat.00, 1
.file "test.c"
.def _notmain;
.scl 2;
.type 32;
.endef
.section ,"xr"
.globl _notmain # -- Begin function notmain
.p2align 4, 0x90
_notmain: # @notmain
# %bb.0:
pushl %ebp
movl %esp, %ebp
popl %ebp
retl
# -- End function
.def _main;
.scl 2;
.type 32;
.endef
.globl _main # -- Begin function main
.p2align 4, 0x90
_main: # @main
# %bb.0:
pushl %ebp
movl %esp, %ebp
calll _notmain
xorl %eax, %eax
popl %ebp
retl
# -- End function
.globl _var3 # @var3
.p2align 2, 0x90
_var3:
.long 7 # 0x7
.globl _var4 # @var4
.p2align 2, 0x90
_var4:
.long 10 # 0xa
.globl _var1 # @var1
.p2align 2, 0x90
_var1:
.long 0 # 0x0
.globl _var2 # @var2
.p2align 2, 0x90
_var2:
.long 0 # 0x0
.addrsig
.addrsig_sym _notmain
why is it missing the pragma clang .section for the variables?
This doesn’t happend when I use the target as i686-pc-linux-gnu. The output for this is as below?
.text
.file "test.c"
.section .myText,"ax",@progbits
.globl notmain # -- Begin function notmain
.p2align 4, 0x90
.type notmain,@function
notmain: # @notmain
.cfi_startproc
# %bb.0:
pushl %ebp
.cfi_def_cfa_offset 8
.cfi_offset %ebp, -8
movl %esp, %ebp
.cfi_def_cfa_register %ebp
popl %ebp
.cfi_def_cfa %esp, 4
retl
.Lfunc_end0:
.size notmain, .Lfunc_end0-notmain
.cfi_endproc
# -- End function
.globl main # -- Begin function main
.p2align 4, 0x90
.type main,@function
main: # @main
.cfi_startproc
# %bb.0:
pushl %ebp
.cfi_def_cfa_offset 8
.cfi_offset %ebp, -8
movl %esp, %ebp
.cfi_def_cfa_register %ebp
pushl %ebx
pushl %eax
.cfi_offset %ebx, -12
calll .L1$pb
.L1$pb:
popl %ebx
.Ltmp0:
addl $_GLOBAL_OFFSET_TABLE_+(.Ltmp0-.L1$pb), %ebx
calll notmain
xorl %eax, %eax
addl $4, %esp
popl %ebx
popl %ebp
.cfi_def_cfa %esp, 4
retl
.Lfunc_end1:
.size main, .Lfunc_end1-main
.cfi_endproc
# -- End function
.type var3,@object # @var3
.section myData,"aw",@progbits
.globl var3
.p2align 2, 0x0
var3:
.long 7 # 0x7
.size var3, 4
.type var4,@object # @var4
.section myRodata,"a",@progbits
.globl var4
.p2align 2, 0x0
var4:
.long 10 # 0xa
.size var4, 4
.type var1,@object # @var1
.section myBSS,"aw",@nobits
.globl var1
.p2align 2, 0x0
var1:
.long 0 # 0x0
.size var1, 4
.type var2,@object # @var2
.globl var2
.p2align 2, 0x0
var2:
.long 0 # 0x0
.size var2, 4
.ident "clang version 18.1.8"
.section ".note.GNU-stack","",@progbits
.addrsig
.addrsig_sym notmain
Can someone support me in figuring out why this happens?