mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-02-12 12:48:59 +00:00
[libc] Move the definitions of the standard IO streams to the platform
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. Reviewed By: lntue, sivachandra Differential Revision: https://reviews.llvm.org/D152983
This commit is contained in:
parent
4e4bd29061
commit
a09bec6459
@ -97,3 +97,10 @@ static GPUFile StdErr(0UL, File::ModeFlags(File::OpenMode::APPEND));
|
||||
File *stderr = &StdErr;
|
||||
|
||||
} // namespace __llvm_libc
|
||||
|
||||
// Provide the external defintitions of the standard IO streams.
|
||||
extern "C" {
|
||||
FILE *stdin = reinterpret_cast<FILE *>(&__llvm_libc::StdIn);
|
||||
FILE *stderr = reinterpret_cast<FILE *>(&__llvm_libc::StdErr);
|
||||
FILE *stdout = reinterpret_cast<FILE *>(&__llvm_libc::StdOut);
|
||||
}
|
||||
|
@ -183,3 +183,10 @@ static LinuxFile StdErr(2, nullptr, STDERR_BUFFER_SIZE, _IONBF, false,
|
||||
File *stderr = &StdErr;
|
||||
|
||||
} // namespace __llvm_libc
|
||||
|
||||
// Provide the external defintitions of the standard IO streams.
|
||||
extern "C" {
|
||||
FILE *stdin = reinterpret_cast<FILE *>(&__llvm_libc::StdIn);
|
||||
FILE *stderr = reinterpret_cast<FILE *>(&__llvm_libc::StdErr);
|
||||
FILE *stdout = reinterpret_cast<FILE *>(&__llvm_libc::StdOut);
|
||||
}
|
||||
|
@ -10,6 +10,4 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
extern "C" {
|
||||
FILE *stderr = reinterpret_cast<FILE *>(__llvm_libc::stderr);
|
||||
}
|
||||
extern "C" FILE *stderr;
|
||||
|
@ -10,6 +10,4 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
extern "C" {
|
||||
FILE *stdin = reinterpret_cast<FILE *>(__llvm_libc::stdin);
|
||||
}
|
||||
extern "C" FILE *stdin;
|
||||
|
@ -10,6 +10,4 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
extern "C" {
|
||||
FILE *stdout = reinterpret_cast<FILE *>(__llvm_libc::stdout);
|
||||
}
|
||||
extern "C" FILE *stdout;
|
||||
|
Loading…
x
Reference in New Issue
Block a user