Page MenuHomeFreeBSD

libsys: add LoongArch support
Needs ReviewPublic

Authored by zhaoxiaoqiang007_gmail.com on Tue, Sep 22, 2:24 PM.
Tags
None
Referenced Files
F174188636: D59894.diff
Thu, Oct 1, 6:03 AM
Unknown Object (File)
Wed, Sep 30, 4:17 AM
Unknown Object (File)
Tue, Sep 29, 4:02 PM
Unknown Object (File)
Tue, Sep 29, 7:52 AM
Unknown Object (File)
Tue, Sep 29, 3:34 AM
Unknown Object (File)
Mon, Sep 28, 10:16 PM
Unknown Object (File)
Mon, Sep 28, 5:29 PM
Unknown Object (File)
Mon, Sep 28, 7:57 AM

Details

Reviewers
jkoshy
kib
brooks
Summary

SYS.h syscall stubs, cerror, vfork and __vdso_gettc for LoongArch.

Signed-off-by: Xiaoqiang Zhao <zhaoxiaoqiang007@gmail.com>

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 77174
Build 74057: arc lint + arc unit

Event Timeline

shipujin.t_gmail.com added inline comments.
lib/libsys/loongarch/SYS.h
40

LoongArch has 8 argument registers, $a0–$a7. If $a7 is used for the syscall number, direct syscalls can only pass arguments in $a0–$a6 (7 registers). If the syscall number were placed in $t0 instead, all of $a0–$a7 could be preserved for arguments.

lib/libsys/loongarch/__vdso_gettc.c
38

u_long is a legacy LP64 type, and style(9) recommends uint64_t for fixed-width values. This architecture currently only has lp64, so there is no functional difference, but new code should not introduce legacy types.

lib/libsys/loongarch/cerror.S
36

Missing .hidden cerror, internal symbol gets exported from libc.so**
.hidden is missing, so cerror is compiled with default visibility and will appear in the .dynsym export table once linked into libc.so (measured: readelf --dyn-syms shows GLOBAL DEFAULT cerror).

Suggested change to:

 ENTRY(cerror)
	.hidden	cerror
lib/libsys/loongarch/cerror.S
36

This is strange. libc export is controlled by versioning script. In particular, cerror should be localized in the final binary.
If true, it might indicate some problem with the build.

lib/libsys/loongarch/SYS.h
48

In your code at https://reviews.freebsd.org/D59890 you use la.pcrel, but here you use la.local. Please make the style consistent. For a minimal change, it is suggested to change la.local here to la.pcrel.

Suggested change to:

1:	la.pcrel	$t1, cerror;				\
lib/libsys/loongarch/vfork.S
50

In your code at https://reviews.freebsd.org/D59890 you use la.pcrel, but here you use la.local. Please make the style consistent. For a minimal change, it is suggested to change la.local here to la.pcrel.

Suggested change to:

1:	la.pcrel	$t1, cerror
lib/libsys/loongarch/cerror.S
36

This is strange. libc export is controlled by versioning script. In particular, cerror should be localized in the final binary.
If true, it might indicate some problem with the build.

Thanks for checking — I verified against the build: the version script
only assigns version nodes to listed symbols (bsd.lib.mk:206 links with
-Wl,--version-script=${VERSION_MAP}, generated from Versions.def +
the Symbol.map files; cerror is in no Symbol.map and no map has a
local: clause). Unlisted globals stay exported. Demo: this file's
cerror.o plus a stub __error (the only objects in the link):

$ ld -shared --version-script=vs.map cerror.o err.o -o libce.so
# vs.map = FBSD_1.0 { global: __error; };
#   (same shape as the generated map: a global list, no local:)
$ readelf --dyn-syms -W libce.so
   4: 0000000000000360    36 FUNC    GLOBAL DEFAULT    9 __error@@FBSD_1.0
   6: 0000000000000320    44 FUNC    GLOBAL DEFAULT    9 cerror

__error is listed in the script (so it gets its version node); cerroris not — and the output splits exactly along that line. Nothing else
is in this DSO, so there is nowhere for cerror to hide.

The arches where cerror IS localized hide it by object visibility, not
the script: amd64 .hidden HIDENAME(cerror), aarch64 .hidden cerror
— if the script hid unlisted symbols, those lines would be dead code.
(riscv lacks .hidden like this file, so it presumably exports cerror
too — not a build problem.)

So the build behaves as; the one-line .hidden cerror here
is the mechanism that localizes it on amd64/aarch64 today. (Making the
script hide unlisted symbols via local:* would be a fine global policy,
but that's a separate discussion.)

lib/libsys/loongarch/cerror.S
36

On my machine the generated Version.map file from lib/libc has the following

FBSDprivate_1.0 {
...
local:
	*;
} FBSD_1.9;

I also checked by adding dummy function to one of the libc source file, and I see

755: 0000000000180d30     6 FUNC    LOCAL  DEFAULT   14 FUUUUU

It is a lot of global symbols in libc sources, but they are all properly scoped in the version script.