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)
Tue, Jun 25, 11:21 AM
Unknown Object (File)
Sun, Jun 23, 9:16 AM
Unknown Object (File)
Sat, Jun 15, 12:16 AM
Unknown Object (File)
Fri, May 31, 1:45 AM
Unknown Object (File)
May 23 2024, 8:17 AM
Unknown Object (File)
May 23 2024, 8:17 AM
Unknown Object (File)
May 23 2024, 8:17 AM
Unknown Object (File)
May 23 2024, 8:17 AM
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 Not Applicable
Unit
Tests Not Applicable

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.

54
55

Remove this blank comment line

56

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

90

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

56

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
56

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.