是否可以在 Linux 中编译带有 MSB 标志的 ELF 文件
Is compiling ELF files with MSB flag possible in Linux
是否可以在 GCC 中编译具有 MSB 字节顺序的二进制文件?如果是这样,它们在执行时会正常工作吗?
正在将评论转变成类似答案的内容。
部分取决于CPU架构。在 SPARC 或 Power 上,您可能会发现 MSB 是默认设置。在 Intel 上,默认情况下绝对是 LSB,您可能不能。
On Intel. If I somehow altered every ELF header entry to MSB in a little-endian binary, would that execute properly?
否;您必须对代码进行许多其他更改才能使其发挥作用。基本上,每个数字都必须从 little-endian 修改为 big-endian。
Would that include instruction addresses, immediate parameters etc.? I would assume that regardless of the ELF flag, these should remain little-endian.
稍加思考,我认为英特尔内核很可能会简单地拒绝执行 MSB ELF 可执行文件。它被编译为期望 LSB 并且知道它不知道如何处理替代方案。要解决这个问题,您必须重建内核和动态加载程序,ld.so.1
。这可能只是您问题的开始。
总的来说,我认为这是徒劳的。在没有相反信息的情况下,我认为您不必担心处理英特尔二进制文件的 MSB ELF headers 的 headers;它们在实践中不会存在。
它不认为它在 System V ABI 中明确说明,但据我所知,ELF 文件应该是本机字节顺序(并且 e_ident[EI_DATA]
描述了使用的字节顺序):
Byte e_ident[EI_DATA]
specifies the data encoding of the
processor-specific data in the object file. The following encodings
are currently defined.
您可能希望特定于处理器的数据采用处理器字节顺序。例如,.got
的内容是特定于处理器的数据,您肯定希望它采用本机字节顺序。
在 Intel 计算机上,您必须使用 ELFDATA2LSB
。
来自System V ABI ~ Intel386 Supplement 4th edition:
For file identification in e_ident
, the Intel386 architecture
requires the following values.
e_ident[EI_CLASS] = ELFCLASS32
e_ident[EI_DATA] = ELFDATA2LSB
来自System V ABI ~ AMD64 supplement Draft 0.99.6:
For file identification in e_ident
, the AMD64 architecture
requires the following values.
e_ident[EI_CLASS] = ELFCLASS64
e_ident[EI_DATA] = ELFDATA2LSB
是否可以在 GCC 中编译具有 MSB 字节顺序的二进制文件?如果是这样,它们在执行时会正常工作吗?
正在将评论转变成类似答案的内容。
部分取决于CPU架构。在 SPARC 或 Power 上,您可能会发现 MSB 是默认设置。在 Intel 上,默认情况下绝对是 LSB,您可能不能。
On Intel. If I somehow altered every ELF header entry to MSB in a little-endian binary, would that execute properly?
否;您必须对代码进行许多其他更改才能使其发挥作用。基本上,每个数字都必须从 little-endian 修改为 big-endian。
Would that include instruction addresses, immediate parameters etc.? I would assume that regardless of the ELF flag, these should remain little-endian.
稍加思考,我认为英特尔内核很可能会简单地拒绝执行 MSB ELF 可执行文件。它被编译为期望 LSB 并且知道它不知道如何处理替代方案。要解决这个问题,您必须重建内核和动态加载程序,ld.so.1
。这可能只是您问题的开始。
总的来说,我认为这是徒劳的。在没有相反信息的情况下,我认为您不必担心处理英特尔二进制文件的 MSB ELF headers 的 headers;它们在实践中不会存在。
它不认为它在 System V ABI 中明确说明,但据我所知,ELF 文件应该是本机字节顺序(并且 e_ident[EI_DATA]
描述了使用的字节顺序):
Byte
e_ident[EI_DATA]
specifies the data encoding of the processor-specific data in the object file. The following encodings are currently defined.
您可能希望特定于处理器的数据采用处理器字节顺序。例如,.got
的内容是特定于处理器的数据,您肯定希望它采用本机字节顺序。
在 Intel 计算机上,您必须使用 ELFDATA2LSB
。
来自System V ABI ~ Intel386 Supplement 4th edition:
For file identification in
e_ident
, the Intel386 architecture requires the following values.e_ident[EI_CLASS] = ELFCLASS32 e_ident[EI_DATA] = ELFDATA2LSB
来自System V ABI ~ AMD64 supplement Draft 0.99.6:
For file identification in
e_ident
, the AMD64 architecture requires the following values.e_ident[EI_CLASS] = ELFCLASS64 e_ident[EI_DATA] = ELFDATA2LSB