Skip to content

lib: add loongarch64 processor support - #556

Open
debianyu wants to merge 1 commit into
linux-audit:masterfrom
debianyu:loongarch64-support
Open

debianyu wants to merge 1 commit into
linux-audit:masterfrom
debianyu:loongarch64-support

Conversation

@debianyu

Copy link
Copy Markdown

What this does

Adds LoongArch64 processor support to the audit userspace library
(libaudit), following the pattern established by aarch64 and riscv.

The Linux kernel has had LoongArch64 support since 5.19. The kernel
headers (linux/audit.h, elf.h) already define EM_LOONGARCH (258)
and AUDIT_ARCH_LOONGARCH64, but audit-userspace does not map these
to a machine type. This patch closes that gap.

Why it matters

Without this patch, audit_determine_machine() returns -4 for
loongarch64 and audit_name_to_syscall() / audit_syscall_to_name()
return nothing. Any audit tool that needs to translate between syscall
numbers and names — ausyscall, aureport, ausearch — silently
fails on a loongarch64 host.

A search of this repository's issues, PRs and git history returns
zero results for "loongarch" or "loongarch64". The gap is complete.

Scope

  • 8 modified files + 1 new file (lib/loongarch64_table.h, 326 syscall
    entries)
  • 421 insertions, 2 deletions
  • LoongArch64 is 64-bit only (no 32-bit variant); the
    audit_determine_machine() logic explicitly rejects 32-bit requests
  • The syscall table is derived from riscv64_table.h (both use the
    generic ABI), minus two RISC-V-specific syscalls
  • Guarded by --with-loongarch64 configure flag, matching the
    --with-arm/--with-aarch64/--with-riscv convention
  • Does not add EM_LOONGARCH or AUDIT_ARCH_LOONGARCH64 definitions —
    these already exist in system kernel headers

Testing

  • Patch applies cleanly to current master (HEAD)
  • All modified files touch only #ifdef WITH_LOONGARCH64 guarded blocks —
    a build without --with-loongarch64 is bit-identical to the unpatched tree

Full native build (x86_64 host)

autoreconf -if
./configure --with-loongarch64 --without-python3 --disable-zos-remote
make -j$(nproc)
cd lib/test && make lookup_test && ./lookup_test
  • configure correctly defines WITH_LOONGARCH64 in config.h
  • make succeeds: loongarch64_table.h (326 entries) processed by gen_tables.c,
    producing 171-line lookup tables; 4 loongarch64 symbols linked into libaudit.so
  • lookup_test passes: "Testing loongarch64_table..." runs without errors

Cross-compilation (loongarch64 target)

Using loongarch64-unknown-linux-gnu-gcc 15.1.0 (from loongson/build-tools):

  • Generated loongarch64_tables.h + gen_tables.h helpers compile cleanly
    for loongarch64 target: file reports ELF 64-bit LSB relocatable, LoongArch

Syscall number spot-check

Syscall Expected Result
io_setup 0 OK
io_destroy 1 OK
openat 56 OK
close 57 OK
read 63 OK
write 64 OK
exit 93 OK
rt_sigreturn 139 OK
riscv_flush_icache absent OK
riscv_hwprobe absent OK

Add LoongArch64 (EM_LOONGARCH 258) support to the audit library,
following the pattern used by aarch64 and riscv.

The LoongArch64 architecture uses the generic syscall ABI (same as
riscv64), so the syscall table is derived from the riscv64 table
minus RISC-V-specific syscalls.

This includes:
- configure.ac: --with-loongarch64 option and WITH_LOONGARCH64 define
- lib/libaudit.h: MACH_LOONGARCH64 in machine_t enum
- lib/libaudit.c: machine determination for loongarch64 (64-bit only)
- lib/lookup_table.c: elf table entry and s2i/i2s dispatch
- lib/machinetab.h: machine name mapping
- lib/Makefile.am: build rules for loongarch64_tables.h
- lib/test/lookup_test.c: table validation test
- lib/syscall-update.txt: syscall source documentation
- lib/loongarch64_table.h: 326 syscall entries (new file)

Signed-off-by: YuPeng <yupeng@kylinos.cn>
@debianyu

Copy link
Copy Markdown
Author

Hi @stevegrubb, friendly ping on this loongarch64 support PR.

Summary of verification:

  • autoreconf + configure --with-loongarch64 + make: clean build on x86_64
  • lookup_test: passes ("Testing loongarch64_table..." without errors)
  • Cross-compilation: generated tables compile for loongarch64 target (GCC 15.1.0,
    ELF 64-bit LSB relocatable, LoongArch)
  • Syscall spot-check: 10/10 correct, RISC-V-specific syscalls correctly absent

The approach follows the existing aarch64/riscv64 pattern with --with-loongarch64
configure flag. Also noting there was a prior loongarch submission (#229 from 2021)
that lacked the configure guard — this PR uses the current upstream convention.

Please let me know if any changes are needed. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant