Page MenuHomeFreeBSD

lib/csu/riscv: Remove separate assembly startup file
Needs ReviewPublic

Authored by arichardson on Aug 21 2024, 10:35 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Nov 14, 4:23 PM
Unknown Object (File)
Wed, Nov 6, 6:15 AM
Unknown Object (File)
Sep 27 2024, 12:00 AM
Unknown Object (File)
Sep 23 2024, 7:32 AM
Unknown Object (File)
Sep 19 2024, 9:07 AM
Unknown Object (File)
Sep 8 2024, 7:32 AM
Unknown Object (File)
Sep 7 2024, 3:29 PM
Unknown Object (File)
Aug 31 2024, 2:04 AM
Subscribers

Details

Reviewers
jrtc27
jhb
Group Reviewers
riscv
Summary

There is no need to do the pointer arithmetic in assembly, when we
can do it in C instead. This removes the separate assembly file and
implements a tiny naked function that sets up gp and calls into C.

This ensures that the object file has all the required attribute set
without having to take care to include directives such as
.section .note.GNU-stack,"",%progbits, etc.
Computation of argv/envv is also understandable now without needing to know
RISC-V assembly code.

Test Plan

Still boots fine, godbolt confirms assembly matches

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 59132
Build 56019: arc lint + arc unit

Event Timeline

lib/csu/riscv/crt1_c.c
50–52
62

used isn't needed, attributes normally come after the return type

72

This constraint makes me nervous. GCC uses "l,S,U" for its call operand, whereas "i" is for immediates. I can't find documentation for what l and U are exactly, but S is "A constraint that matches an absolute symbolic address." Is there a reason not to just put the __start inline and mark it __used?

lib/csu/riscv/crt1_c.c
62

I guess it is not needed since it is the entry point, just being paranoid since I've had a few cases lately where LTO+linker GC removed functions I assumed were used.

72

I recently came across the recommendation to use "i" in Arm documentation, I believe it was the following:

https://developer.arm.com/documentation/101754/0622/armclang-Reference/armclang-inline-assembler/Symbol-references-and-branches-into-and-out-of-inline-assembly?lang=en

This was rather helpful since I was using it to call a C++ function and it takes care of C++ name mangling. It works as expected on both Clang and GCC (even with old versions): https://godbolt.org/z/ejbjsT3Yv

lib/csu/riscv/crt1_c.c
50–52

I kept the parens here since they don't do any harm but can remove them if needed.