LLVM:来自数据布局的成员对齐
LLVM: member alignment from data-layout
我需要了解如何从数据布局中获取非压缩文字结构中的成员对齐方式。
按照规定here,可以获取此信息。
比如我有这段代码:
; ModuleID = 'fy4vsjaw.hjq.cpp'
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux"
%struct.S = type { i8, i64 }
; Function Attrs: nounwind uwtable
define { i8, i64 } @foo() #0 !dbg !4 {
在行%struct.S = type { i8, i64 }
中,这里两个成员之间的填充是多少?
我希望是 32 位或 64 位,但我想确定一下。
谢谢!
确实是数据布局里面写的。如data layout spec中指定的,这部分i64:64
的布局表示int64是64位对齐的。
在结构%struct.S = type { i8, i64 }
中,因此在两个字段之间有一个 7 字节的填充。
以编程方式,可以通过索引获取成员的偏移量:
uint64_t GetOffset(llvm::Module* mod, llvm::StructType* st, uint32_t int index) {
return mod->getDataLayout()->getStructLayout(st)->getElementOffset(index);
}
我需要了解如何从数据布局中获取非压缩文字结构中的成员对齐方式。
按照规定here,可以获取此信息。
比如我有这段代码:
; ModuleID = 'fy4vsjaw.hjq.cpp'
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux"
%struct.S = type { i8, i64 }
; Function Attrs: nounwind uwtable
define { i8, i64 } @foo() #0 !dbg !4 {
在行%struct.S = type { i8, i64 }
中,这里两个成员之间的填充是多少?
我希望是 32 位或 64 位,但我想确定一下。
谢谢!
确实是数据布局里面写的。如data layout spec中指定的,这部分i64:64
的布局表示int64是64位对齐的。
在结构%struct.S = type { i8, i64 }
中,因此在两个字段之间有一个 7 字节的填充。
以编程方式,可以通过索引获取成员的偏移量:
uint64_t GetOffset(llvm::Module* mod, llvm::StructType* st, uint32_t int index) {
return mod->getDataLayout()->getStructLayout(st)->getElementOffset(index);
}