.net core 如何使用&&引用;在CIL.data声明中

.net core 如何使用&&引用;在CIL.data声明中,.net-core,compiler-construction,cil,.net Core,Compiler Construction,Cil,我正在编写一个针对通用中间语言的编译器,并希望为全局语言使用.data-声明。我指的是第II.16.3.1节 如何使用“标签地址”?以下内容使用.NET Core的ilasm进行组装: .assembly extern mscorlib { .ver 4:0:0:0 } .assembly 'string' { } .module 'string' .data hello_world_data = { int8(72), int8(101), int8(108), int8(108),

我正在编写一个针对通用中间语言的编译器,并希望为全局语言使用
.data
-声明。我指的是第II.16.3.1节

如何使用“标签地址”?以下内容使用.NET Core的ilasm进行组装:

.assembly extern mscorlib
{
    .ver 4:0:0:0
}
.assembly 'string'
{
}
.module 'string'

.data hello_world_data = { int8(72), int8(101), int8(108), int8(108), int8(111), int8(32), int8(87), int8(111), int8(114), int8(108), int8(100), int8(33), int8(0) }

.field static int8 hello_world at hello_world_data

.data addr_of_data = &(hello_world_data)

.field static int8* hello_world_ptr at addr_of_data

.method public static default int32 main () cil managed {
    .entrypoint

    ldc.i4.0
    ret
}
但是当我尝试执行上面的代码时,我得到以下错误消息(在Linux上使用.NET Core):


有什么想法/帮助吗?

如果这对您很重要,我建议您在回购协议中提交一个问题

我假设这在Windows之外不起作用的原因是,这些指令通过重新定位生成数据(在可执行文件中的位置,一旦可执行文件加载到内存中,就需要用实际地址修复这些位置)。由于.NET中可执行文件的格式基于Windows PE格式,因此重新定位由Windows在加载可执行文件时进行处理

在Windows之外,CoreCLR附带了一个小型的“Windows加载程序模拟器”,它以Windows加载.NET可执行文件的方式加载这些文件。但它可能忽略了对这些搬迁的处理。否则,IL格式不会生成重定位


但是这些重新定位在很多地方都会有问题(我完全希望像IL链接器这样的工具会错过它们并损坏它们,我假设Mono也没有处理这些,它们对于AOT编译来说会有问题,等等).

Mmmmh有趣的是,在使用.NET Framework的Windows上,ilasm工作正常。我不仅在.NET Core上测试了这一点,还使用了Mono(在Linux上也是如此)。它对单声道也不起作用。这就是为什么我猜我做错了什么。在.NET Core上,我可以组装il,但运行生成的
.exe
-文件会导致
BadImageFormatException
。这些功能不经常使用,因此某些平台不支持它们。使用嵌入式资源可能更好,尽管它更复杂。
Unhandled exception. System.BadImageFormatException: Could not load file or assembly '/home/lou/uni/proj/stuff/tests/test-global-arrays/string.exe'. An attempt was made to load a program with an incorrect format.

File name: '/home/lou/uni/proj/stuff/tests/test-global-arrays/string.exe'


[1]    12019 abort (core dumped)  dotnet string.exe