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) {...@@ -337,6 +337,7 @@ pub const ET = extern enum(u16) {
337/// All integers are native endian.337/// All integers are native endian.
338pub const Header = struct {338pub const Header = struct {
339 endian: builtin.Endian,339 endian: builtin.Endian,
340 machine: EM,
340 is_64: bool,341 is_64: bool,
341 entry: u64,342 entry: u64,
342 phoff: u64,343 phoff: u64,
...@@ -387,8 +388,14 @@ pub const Header = struct {...@@ -387,8 +388,14 @@ pub const Header = struct {
387 else => return error.InvalidElfClass,388 else => return error.InvalidElfClass,
388 };389 };
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
390 return @as(Header, .{396 return @as(Header, .{
391 .endian = endian,397 .endian = endian,
398 .machine = machine,
392 .is_64 = is_64,399 .is_64 = is_64,
393 .entry = int(is_64, need_bswap, hdr32.e_entry, hdr64.e_entry),400 .entry = int(is_64, need_bswap, hdr32.e_entry, hdr64.e_entry),
394 .phoff = int(is_64, need_bswap, hdr32.e_phoff, hdr64.e_phoff),401 .phoff = int(is_64, need_bswap, hdr32.e_phoff, hdr64.e_phoff),
...@@ -1518,6 +1525,8 @@ pub const EM = extern enum(u16) {...@@ -1518,6 +1525,8 @@ pub const EM = extern enum(u16) {
15181525
1519 /// Linux kernel bpf virtual machine1526 /// Linux kernel bpf virtual machine
1520 _BPF = 247,1527 _BPF = 247,
1528
1529 _,
1521};1530};
15221531
1523/// Section data should be writable during execution.1532/// Section data should be writable during execution.