-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[libc][uefi] add crt1 #132150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[libc][uefi] add crt1 #132150
Changes from 2 commits
b12c594
dee779f
7428fe0
bf566bb
40a26a0
e5a4692
d963ce2
4ccc169
65da577
553ec1b
6648c0c
0596ada
f87345a
0a47352
ae46dfc
5e4c64f
74dd600
3aaccf0
b5dbce3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,46 @@ | ||||||||||
function(add_startup_object name) | ||||||||||
cmake_parse_arguments( | ||||||||||
"ADD_STARTUP_OBJECT" | ||||||||||
"ALIAS" # Option argument | ||||||||||
"SRC" # Single value arguments | ||||||||||
"DEPENDS;COMPILE_OPTIONS" # Multi value arguments | ||||||||||
${ARGN} | ||||||||||
) | ||||||||||
|
||||||||||
get_fq_target_name(${name} fq_target_name) | ||||||||||
if(ADD_STARTUP_OBJECT_ALIAS) | ||||||||||
get_fq_deps_list(fq_dep_list ${ADD_STARTUP_OBJECT_DEPENDS}) | ||||||||||
add_library(${fq_target_name} ALIAS ${fq_dep_list}) | ||||||||||
return() | ||||||||||
endif() | ||||||||||
|
||||||||||
add_object_library( | ||||||||||
${name} | ||||||||||
SRCS ${ADD_STARTUP_OBJECT_SRC} | ||||||||||
COMPILE_OPTIONS ${ADD_STARTUP_OBJECT_COMPILE_OPTIONS} | ||||||||||
${ADD_STARTUP_OBJECT_UNPARSED_ARGUMENTS} | ||||||||||
DEPENDS ${ADD_STARTUP_OBJECT_DEPENDS} | ||||||||||
) | ||||||||||
set_target_properties( | ||||||||||
${fq_target_name} | ||||||||||
PROPERTIES | ||||||||||
OUTPUT_NAME ${name}.o | ||||||||||
) | ||||||||||
endfunction() | ||||||||||
|
||||||||||
add_startup_object( | ||||||||||
crt1 | ||||||||||
SRCS | ||||||||||
crt1.cpp | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: formatting.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is done |
||||||||||
) | ||||||||||
|
||||||||||
add_custom_target(libc-startup) | ||||||||||
set(startup_components crt1) | ||||||||||
foreach(target IN LISTS startup_components) | ||||||||||
set(fq_target_name libc.startup.uefi.${target}) | ||||||||||
add_dependencies(libc-startup ${fq_target_name}) | ||||||||||
install(FILES $<TARGET_OBJECTS:${fq_target_name}> | ||||||||||
DESTINATION ${LIBC_INSTALL_LIBRARY_DIR} | ||||||||||
RENAME $<TARGET_PROPERTY:${fq_target_name},OUTPUT_NAME> | ||||||||||
COMPONENT libc) | ||||||||||
endforeach() |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,29 @@ | ||||||||||||||||||||||||||||||
//===-- Implementation of crt for UEFI ----------------------------------===// | ||||||||||||||||||||||||||||||
// | ||||||||||||||||||||||||||||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||||||||||||||||||||||||||||||
// See https://llvm.org/LICENSE.txt for license information. | ||||||||||||||||||||||||||||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||||||||||||||||||||||||||||||
// | ||||||||||||||||||||||||||||||
//===--------------------------------------------------------------------===// | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: formatting.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is done |
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
#include "include/llvm-libc-macros/stdlib-macros.h" | ||||||||||||||||||||||||||||||
#include "include/llvm-libc-types/EFI_HANDLE.h" | ||||||||||||||||||||||||||||||
#include "include/llvm-libc-types/EFI_STATUS.h" | ||||||||||||||||||||||||||||||
#include "include/llvm-libc-types/EFI_SYSTEM_TABLE.h" | ||||||||||||||||||||||||||||||
#include "src/__support/macros/config.h" | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
EFI_HANDLE efi_image_handle; | ||||||||||||||||||||||||||||||
EFI_SYSTEM_TABLE *efi_system_table; | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't be placing new symbols into the global namespace, that's problematic from C standard perspective, so these symbols need to prefixed with
Suggested change
Do you know if there's a common convention for accessing these symbols? I looked at EDK2 and there it seems like these symbols are usually passed through explicitly as input arguments to functions that need them, but I don't know if there are other examples other than EDK2. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There isn't a standard way so this was the compromise. I could join the UEFI forum IRC and inquire about it but I wouldn't be surprised if it's a "there is no standard" solution. My thinking was this would at least be an easily recognizable way programs could access the UEFI stuff if they need it for things like graphics or networking. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also you need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I got symbol not found errors with that when I tried linking against the start file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I got it to build correctly with extern. |
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
extern "C" int main(int argc, char **argv, char **envp); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
extern "C" EFI_STATUS EfiMain(EFI_HANDLE ImageHandle, | ||||||||||||||||||||||||||||||
EFI_SYSTEM_TABLE *SystemTable) { | ||||||||||||||||||||||||||||||
efi_image_handle = ImageHandle; | ||||||||||||||||||||||||||||||
efi_system_table = SystemTable; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
main(0, NULL, NULL); | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is done |
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// TODO: convert the return value of main to EFI_STATUS | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How involved is this? Is there a reason for not doing this right away? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not entirely sure since there's no errno numbers defined so we'll have to make them up. I didn't want to complicate things too much in this PR so this is just a MVP. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's C standard errno values if nothing else. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was going to add something to convert the error codes, where should it live in |
||||||||||||||||||||||||||||||
return 0; // TODO: EFI_SUCCESS | ||||||||||||||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I apparently missed that each of the targets currently has their own definition of this. Please add a todo referencing #133156 (the bug I've filed for this)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done