Page MenuHomeFreeBSD

csu: Implement _start using as to satisfy unwinders on x86_64
ClosedPublic

Authored by dchagin on Jun 27 2023, 11:36 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Nov 8, 4:36 AM
Unknown Object (File)
Wed, Oct 16, 3:45 PM
Unknown Object (File)
Oct 1 2024, 1:14 PM
Unknown Object (File)
Oct 1 2024, 7:59 AM
Unknown Object (File)
Oct 1 2024, 1:31 AM
Unknown Object (File)
Sep 30 2024, 7:35 AM
Unknown Object (File)
Sep 27 2024, 11:36 PM
Unknown Object (File)
Sep 27 2024, 7:21 PM
Subscribers

Details

Summary

The right unwinding stop indicator should be CFI-undefined PC.
https://dwarfstd.org/doc/Dwarf3.pdf - page 118:
If a Return Address register is defined in the virtual unwind table,
and its rule is undefined (for example, by DW_CFA_undefined), then
there is no return address and no call address, and the virtual
unwind of stack activations is complete.

This requires the crt code be built with unwind tables, for that remove
-fno-asynchronous-unwind-tables to enable unwind tables generation.

PR: 241562, 246322, 246537

Test Plan

Not tested with GCRT

Diff Detail

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

Event Timeline

Please add the comments, mostly by copying/pasting the C statements for calculating each __libc_start1 arg. Also please add a comment with _start() prototype.

GCRT is the gcrt1.o compilation, it is a special kind of crt1.o intended for (almost dead) sample-based userspace profiling, AKA cc -pg. This is where profiling libraries like libc_p.a were needed.

lib/csu/amd64/crt1_s.S
30

No need to add this to new files

45

Sorry, but please keep this in .c.

dchagin added inline comments.
lib/csu/amd64/crt1_s.S
45

whoops, Im missed that __progname is a pointer to an ampty string

In D40780#927982, @kib wrote:

Please add the comments, mostly by copying/pasting the C statements for calculating each __libc_start1 arg. Also please add a comment with _start() prototype.

GCRT is the gcrt1.o compilation, it is a special kind of crt1.o intended for (almost dead) sample-based userspace profiling, AKA cc -pg. This is where profiling libraries like libc_p.a were needed.

Thank you, it looks like with GCRT test compiles and even runs,
however Im a bit confused by eprol: - seems that int3 at the end of _start in GCRT case should be avoided?

lib/csu/amd64/crt1_s.S
45

Still, I suggest to keep crt1_c.c and have environ and __progname defined there.

53
54

Remove this blank comment line

55

Add a line with register names for args like
* %rdi %rsi

89

int3 after the __libc_start1_gcrt makes the same sense as after __libc_start1

Done, Makefile a bit ugly due to source inversion

lib/csu/amd64/crt1_s.S
36

The program entry point

55

Still not done

Isn't stack alignment broken?

Hope fixed, comment about stack added

In D40780#928374, @kib wrote:

Isn't stack alignment broken?

it should not due to pushq %rbp, xregs_sig test passed

lib/csu/amd64/crt1_s.S
55

Because I add it below, before __libc_start_gcrt

kib added inline comments.
lib/csu/amd64/crt1_s.S
63

Perhaps add a comment that this does not work for large memory model.

This revision is now accepted and ready to land.Jun 29 2023, 12:23 AM
This revision was automatically updated to reflect the committed changes.
dchagin marked an inline comment as done.