authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-03-11 14:30:06-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2021-03-11 14:30:06-05:00
logb1a22fdbab4a30a91cd628037f2c7e15978607a5
treea39ca5fb2a19997c3eecd17593c4b223c6bac4fd
parentf2b96782ecdc9e2f8740eb7d294203b2a585ea52
parent24e5959840c790ec74665d22a21d82b68418bc57
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #8193 from kivikakk/elf-expose-em

elf: expose machine field in ELF header

1 files changed, 9 insertions(+), 0 deletions(-)

lib/std/elf.zig+9
......@@ -337,6 +337,7 @@ pub const ET = extern enum(u16) {
337337/// All integers are native endian.
338338pub const Header = struct {
339339 endian: builtin.Endian,
340 machine: EM,
340341 is_64: bool,
341342 entry: u64,
342343 phoff: u64,
......@@ -387,8 +388,14 @@ pub const Header = struct {
387388 else => return error.InvalidElfClass,
388389 };
389390
391 const machine = if (need_bswap) blk: {
392 const value = @enumToInt(hdr32.e_machine);
393 break :blk @intToEnum(EM, @byteSwap(@TypeOf(value), value));
394 } else hdr32.e_machine;
395
390396 return @as(Header, .{
391397 .endian = endian,
398 .machine = machine,
392399 .is_64 = is_64,
393400 .entry = int(is_64, need_bswap, hdr32.e_entry, hdr64.e_entry),
394401 .phoff = int(is_64, need_bswap, hdr32.e_phoff, hdr64.e_phoff),
......@@ -1518,6 +1525,8 @@ pub const EM = extern enum(u16) {
15181525
15191526 /// Linux kernel bpf virtual machine
15201527 _BPF = 247,
1528
1529 _,
15211530};
15221531
15231532/// Section data should be writable during execution.