This is an archive of the discontinued LLVM Phabricator instance.

[libc] Move the definitions of the standard IO streams to the platform
ClosedPublic

Authored by jhuber6 on Jun 14 2023, 5:03 PM.

Details

Summary

This patch moves the definitions of the standard IO streams to the
platform file definition. This is necessary because previously we had a
level of indirection where the stream's FILE * was initialized based
on the pointer to the internal __llvm_libc version. This cannot be
resolved ahead of time by the linker because the address will not be
known until runtime. This caused the previous implementation to emit a
global constructor to initialize the pointer to the actual FILE *. By
moving these definitions so that we can bind their address to the
original file type we can avoid this global constructor.

This file keeps the entrypoints, but makes them empty files only
containing an external reference. This is so they still appear as
entrypoints and get emitted as declarations in the generated headers.

Diff Detail

Event Timeline

jhuber6 created this revision.Jun 14 2023, 5:03 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJun 14 2023, 5:03 PM
jhuber6 requested review of this revision.Jun 14 2023, 5:03 PM

I don't know if keeping the entrypoints is necessary but I don't know how to make it emit the extern FILE *stderr definitions without them.

jhuber6 updated this revision to Diff 531594.Jun 14 2023, 7:46 PM

Fix extern C

lntue accepted this revision.Jun 14 2023, 8:46 PM
This revision is now accepted and ready to land.Jun 14 2023, 8:46 PM
sivachandra accepted this revision.Jun 14 2023, 10:35 PM

Thanks for catching the problem and the patch to fix it.