Skip to content

Commit

Permalink
Merge pull request #974 from Billy99/billy99-arch-ppc64-s390x
Browse files Browse the repository at this point in the history
aya: add archs powerpc64 and s390x to aya
  • Loading branch information
alessandrod committed Aug 27, 2024
2 parents 4362020 + 4dc4b5c commit ab5e688
Show file tree
Hide file tree
Showing 21 changed files with 534 additions and 144 deletions.
6 changes: 6 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ linker = "arm-linux-gnueabihf-gcc"

[target.aarch64-unknown-linux-musl]
linker = "aarch64-linux-musl-gcc"

[target.powerpc64le-unknown-linux-gnu]
linker = "powerpc64le-linux-gnu-gcc"

[target.s390x-unknown-linux-gnu]
linker = "s390x-linux-gnu-gcc"
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ jobs:
- aarch64-unknown-linux-gnu
- armv7-unknown-linux-gnueabi
- riscv64gc-unknown-linux-gnu
- powerpc64le-unknown-linux-gnu
- s390x-unknown-linux-gnu
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -135,6 +137,8 @@ jobs:
- aarch64
- arm
- riscv64
- powerpc64
- s390x
target:
- bpfel-unknown-none
- bpfeb-unknown-none
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ default-members = [

# ebpf crates are omitted; they must be built with:
# --target bpfe{b,l}-unknown-none
# CARGO_CFG_BPF_TARGET_ARCH={x86_64,aarch64,arm,riscv64}
# CARGO_CFG_BPF_TARGET_ARCH={x86_64,aarch64,arm,riscv64,powerpc64,s390x}
]

[workspace.package]
Expand Down
5 changes: 5 additions & 0 deletions aya-log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -997,9 +997,14 @@ mod test {
len += "ipv6: ".write(&mut input[len..]).unwrap().get();
len += DisplayHint::Ip.write(&mut input[len..]).unwrap().get();
// 2001:db8::1:1 as u16 array
#[cfg(target_endian = "little")]
let ipv6_arr: [u16; 8] = [
0x2001, 0x0db8, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001,
];
#[cfg(target_endian = "big")]
let ipv6_arr: [u16; 8] = [
0x0120, 0xb80d, 0x0000, 0x0000, 0x0000, 0x0000, 0x0100, 0x0100,
];
len += ipv6_arr.write(&mut input[len..]).unwrap().get();

_ = len;
Expand Down
152 changes: 131 additions & 21 deletions aya-obj/src/btf/btf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1110,11 +1110,18 @@ mod tests {

#[test]
fn test_parse_header() {
let data: &[u8] = &[
0x9f, 0xeb, 0x01, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x54,
0x2a, 0x00, 0x64, 0x54, 0x2a, 0x00, 0x10, 0x64, 0x1c, 0x00,
];
let header = unsafe { read_btf_header(data) };
let header = btf_header {
magic: 0xeb9f,
version: 0x01,
flags: 0x00,
hdr_len: 0x18,
type_off: 0x00,
type_len: 0x2a5464,
str_off: 0x2a5464,
str_len: 0x1c6410,
};
let data = unsafe { bytes_of::<btf_header>(&header).to_vec() };
let header = unsafe { read_btf_header(&data) };
assert_eq!(header.magic, 0xeb9f);
assert_eq!(header.version, 0x01);
assert_eq!(header.flags, 0x00);
Expand All @@ -1129,6 +1136,7 @@ mod tests {
fn test_parse_btf() {
// this generated BTF data is from an XDP program that simply returns XDP_PASS
// compiled using clang
#[cfg(target_endian = "little")]
let data: &[u8] = &[
0x9f, 0xeb, 0x01, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x01,
0x00, 0x00, 0x0c, 0x01, 0x00, 0x00, 0xe1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Expand Down Expand Up @@ -1168,35 +1176,135 @@ mod tests {
0x5a, 0x45, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x5f, 0x00, 0x5f, 0x6c, 0x69, 0x63,
0x65, 0x6e, 0x73, 0x65, 0x00, 0x6c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x00,
];
#[cfg(target_endian = "big")]
let data: &[u8] = &[
0xeb, 0x9f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x0c, 0x00, 0x00, 0x01, 0x0c, 0x00, 0x00, 0x00, 0xe1, 0x00, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x04, 0x00,
0x00, 0x06, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x03,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00,
0x00, 0x20, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x40,
0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00,
0x00, 0x30, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x3f,
0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0xa0, 0x00, 0x00, 0x00, 0x4e, 0x08, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x54, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x00,
0x00, 0x01, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x61, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x65, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00,
0x00, 0x20, 0x00, 0x00, 0x00, 0x69, 0x0c, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05,
0x00, 0x00, 0x00, 0xb7, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00,
0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,
0x00, 0xbc, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x20,
0x00, 0x00, 0x00, 0xd0, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00, 0x00, 0xd9, 0x0f, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x78,
0x64, 0x70, 0x5f, 0x6d, 0x64, 0x00, 0x64, 0x61, 0x74, 0x61, 0x00, 0x64, 0x61, 0x74,
0x61, 0x5f, 0x65, 0x6e, 0x64, 0x00, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x6d, 0x65, 0x74,
0x61, 0x00, 0x69, 0x6e, 0x67, 0x72, 0x65, 0x73, 0x73, 0x5f, 0x69, 0x66, 0x69, 0x6e,
0x64, 0x65, 0x78, 0x00, 0x72, 0x78, 0x5f, 0x71, 0x75, 0x65, 0x75, 0x65, 0x5f, 0x69,
0x6e, 0x64, 0x65, 0x78, 0x00, 0x65, 0x67, 0x72, 0x65, 0x73, 0x73, 0x5f, 0x69, 0x66,
0x69, 0x6e, 0x64, 0x65, 0x78, 0x00, 0x5f, 0x5f, 0x75, 0x33, 0x32, 0x00, 0x75, 0x6e,
0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x20, 0x69, 0x6e, 0x74, 0x00, 0x63, 0x74, 0x78,
0x00, 0x69, 0x6e, 0x74, 0x00, 0x78, 0x64, 0x70, 0x5f, 0x70, 0x61, 0x73, 0x73, 0x00,
0x78, 0x64, 0x70, 0x2f, 0x70, 0x61, 0x73, 0x73, 0x00, 0x2f, 0x68, 0x6f, 0x6d, 0x65,
0x2f, 0x64, 0x61, 0x76, 0x65, 0x2f, 0x64, 0x65, 0x76, 0x2f, 0x62, 0x70, 0x66, 0x64,
0x2f, 0x62, 0x70, 0x66, 0x2f, 0x78, 0x64, 0x70, 0x5f, 0x70, 0x61, 0x73, 0x73, 0x2e,
0x62, 0x70, 0x66, 0x2e, 0x63, 0x00, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75,
0x72, 0x6e, 0x20, 0x58, 0x44, 0x50, 0x5f, 0x50, 0x41, 0x53, 0x53, 0x3b, 0x00, 0x63,
0x68, 0x61, 0x72, 0x00, 0x5f, 0x5f, 0x41, 0x52, 0x52, 0x41, 0x59, 0x5f, 0x53, 0x49,
0x5a, 0x45, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x5f, 0x00, 0x5f, 0x6c, 0x69, 0x63,
0x65, 0x6e, 0x73, 0x65, 0x00, 0x6c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x00,
];
assert_eq!(data.len(), 517);
let btf = Btf::parse(data, Endianness::default()).unwrap_or_else(|e| panic!("{}", e));
let data2 = btf.to_bytes();
assert_eq!(data2.len(), 517);
assert_eq!(data, data2);

let ext_data: &[u8] = &[
0x9f, 0xeb, 0x01, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00,
0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x72, 0x00, 0x00, 0x00, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0x72, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7b, 0x00,
0x00, 0x00, 0xa2, 0x00, 0x00, 0x00, 0x05, 0x2c, 0x00, 0x00,
];
const FUNC_LEN: u32 = 0x14;
const LINE_INFO_LEN: u32 = 0x1c;
const CORE_RELO_LEN: u32 = 0;
const DATA_LEN: u32 = (FUNC_LEN + LINE_INFO_LEN + CORE_RELO_LEN) / 4;
struct TestStruct {
_header: btf_ext_header,
_data: [u32; DATA_LEN as usize],
}
let test_data = TestStruct {
_header: btf_ext_header {
magic: 0xeb9f,
version: 1,
flags: 0,
hdr_len: 0x20,
func_info_off: 0,
func_info_len: FUNC_LEN,
line_info_off: FUNC_LEN,
line_info_len: LINE_INFO_LEN,
core_relo_off: FUNC_LEN + LINE_INFO_LEN,
core_relo_len: CORE_RELO_LEN,
},
_data: [
0x00000008u32,
0x00000072u32,
0x00000001u32,
0x00000000u32,
0x00000007u32,
0x00000010u32,
0x00000072u32,
0x00000001u32,
0x00000000u32,
0x0000007bu32,
0x000000a2u32,
0x00002c05u32,
],
};
let ext_data = unsafe { bytes_of::<TestStruct>(&test_data).to_vec() };

assert_eq!(ext_data.len(), 80);
let _: BtfExt = BtfExt::parse(ext_data, Endianness::default(), &btf)
let _: BtfExt = BtfExt::parse(&ext_data, Endianness::default(), &btf)
.unwrap_or_else(|e| panic!("{}", e));
}

#[test]
fn parsing_older_ext_data() {
let btf_data = [
159, 235, 1, 0, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
];
let btf_ext_data = [
159, 235, 1, 0, 24, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 4, 0, 0, 0, 4, 0, 0, 0, 8, 0, 0,
0, 16, 0, 0, 0,
];
const TYPE_LEN: u32 = 0;
const STR_LEN: u32 = 1;
struct BtfTestStruct {
_header: btf_header,
_data: [u8; (TYPE_LEN + STR_LEN) as usize],
}
let btf_test_data = BtfTestStruct {
_header: btf_header {
magic: 0xeb9f,
version: 0x01,
flags: 0x00,
hdr_len: 24,
type_off: 0,
type_len: TYPE_LEN,
str_off: TYPE_LEN,
str_len: TYPE_LEN + STR_LEN,
},
_data: [0x00u8],
};
let btf_data = unsafe { bytes_of::<BtfTestStruct>(&btf_test_data).to_vec() };

const FUNC_INFO_LEN: u32 = 4;
const LINE_INFO_LEN: u32 = 4;
const CORE_RELO_LEN: u32 = 16;
let ext_header = btf_ext_header {
magic: 0xeb9f,
version: 1,
flags: 0,
hdr_len: 24,
func_info_off: 0,
func_info_len: FUNC_INFO_LEN,
line_info_off: FUNC_INFO_LEN,
line_info_len: LINE_INFO_LEN,
core_relo_off: FUNC_INFO_LEN + LINE_INFO_LEN,
core_relo_len: CORE_RELO_LEN,
};
let btf_ext_data = unsafe { bytes_of::<btf_ext_header>(&ext_header).to_vec() };

let btf = Btf::parse(&btf_data, Endianness::default()).unwrap();
let btf_ext = BtfExt::parse(&btf_ext_data, Endianness::default(), &btf).unwrap();
assert_eq!(btf_ext.func_info_rec_size(), 8);
Expand Down Expand Up @@ -1701,9 +1809,11 @@ mod tests {
Btf::parse(&raw, Endianness::default()).unwrap();
}

// Not possible to emulate file system file "/sys/kernel/btf/vmlinux" as big endian, so skip
#[test]
#[cfg(feature = "std")]
#[cfg_attr(miri, ignore = "`open` not available when isolation is enabled")]
#[cfg(target_endian = "little")]
fn test_read_btf_from_sys_fs() {
let btf = Btf::parse_file("/sys/kernel/btf/vmlinux", Endianness::default()).unwrap();
let task_struct_id = btf
Expand Down
2 changes: 1 addition & 1 deletion aya-obj/src/btf/relocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ impl ComputedRelocation {
}
#[cfg(target_endian = "big")]
FieldLShift64 => {
value.value = (8 - byte_size) * 8 + (bit_off - byte_off * 8);
value.value = ((8 - byte_size) * 8 + (bit_off - byte_off * 8)) as u64;
}
FieldRShift64 => {
value.value = 64 - bit_size as u64;
Expand Down
Loading

0 comments on commit ab5e688

Please sign in to comment.