[llvm-dev] How to create global symbol from record offset

Nat! via llvm-dev llvm-dev at lists.llvm.org
Tue Oct 27 04:39:22 PDT 2015


I would like to create something like this (x86_64)

	.section	__DATA,__data
	.align	4
_a:
	.long	18

	.globl	_b
_b:
	.long	48


If you like to notice, there is no alignment between _a and _b.
_b is basically offseting into a record structure.


----

When I use two discrete structs, I get .aligns and I also don't trust 
the tools to keep the two globals together.


%struct.a = type { i32 }
%struct.b = type { i32 }

@a = global %struct.a { i32 1 }, align 4
@b = global %struct.b { i32 848 }, align 4


----

What I don't want is to introduce a global pointer like this

%struct.c = type { %struct.a, %struct.b }
%struct.a = type { i32 }
%struct.b = type { i32 }

@c = internal global %struct.c { %struct.a { i32 18 }, %struct.b { i32 
48 } }, align 4
@p_b = global %struct.b* bitcast (i32* getelementptr inbounds 
(%struct.c* @c, i64 0, i32 1, i32 0) to %struct.b*), align 8


Thanks for any hints how to do this.

Ciao
    Nat!





More information about the llvm-dev mailing list