This is an archive of the discontinued LLVM Phabricator instance.

[libc] Initiliaze the global pointer in riscv startup code.
ClosedPublic

Authored by sivachandra on May 26 2023, 1:10 AM.

Diff Detail

Event Timeline

sivachandra created this revision.May 26 2023, 1:10 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMay 26 2023, 1:10 AM
sivachandra requested review of this revision.May 26 2023, 1:10 AM
jrtc27 added a comment.EditedMay 26 2023, 1:15 AM
  1. Why store in memory on the stack only to load it again?
  2. Depending on how this is compiled it could use the GOT which isn't a good idea
  3. Dollars in a C identifier sound like a bad idea
  4. Relaxations need to be disabled for the address calculation specifically otherwise it will be relaxed to be GP-relative, which is clearly unhelpful
  5. Why is it declared as pointing to an intptr_t instead of being the usual char[]?

In short this really just needs to be done in assembly as the standard .option push; .option norelax; lla gp, __global_pointer$; .option pop.

I agree with Jessica. Assembly or inline assembly will read better.

Update as per the suggestion.

In short this really just needs to be done in assembly as the standard .option push; .option norelax; lla gp, __global_pointer$; .option pop.

Thanks for the suggestion. I have updated now to use this exact snippet.

mikhail.ramalho accepted this revision.Jun 27 2023, 6:04 AM

I've finally got around to testing this patch and it fixes the segfault I was having with clang 15 on visionfive 2.

This revision is now accepted and ready to land.Jun 27 2023, 6:04 AM

Rebase and disable sprintf_test.hermetic as it is failing on riscv.

This revision was landed with ongoing or failed builds.Jul 5 2023, 12:32 AM
This revision was automatically updated to reflect the committed changes.