-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[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 1 commit
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 | ||||||||||
|
SRCS | |
crt1.cpp | |
SRCS | |
crt1.cpp |
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.
This is done
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,65 @@ | ||||||||||||||||||||||||||||||
//===-- 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 | ||||||||||||||||||||||||||||||
// | ||||||||||||||||||||||||||||||
//===--------------------------------------------------------------------===// | ||||||||||||||||||||||||||||||
|
//===-- 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 | |
// | |
//===--------------------------------------------------------------------===// | |
//===-- 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 comment
The reason will be displayed to describe this comment to others. Learn more.
This is done
Outdated
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.
Can you point me to documentation for these symbols? I couldn't find anything in the documentation for Microsoft's link
.
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.
It seems to come from MinGW
Outdated
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.
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 __llvm_libc_
.
EFI_HANDLE efi_image_handle; | |
EFI_SYSTEM_TABLE *efi_system_table; | |
EFI_HANDLE __llvm_libc_efi_image_handle; | |
EFI_SYSTEM_TABLE *__llvm_libc_efi_system_table; |
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Also you need extern "C"
for these symbols to avoid mangling.
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 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 comment
The reason will be displayed to describe this comment to others. Learn more.
I got it to build correctly with extern.
Outdated
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.
Nit:
main(0, NULL, NULL); | |
main(0, nullptr, nullptr); |
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.
This is done
Outdated
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.
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 comment
The 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 comment
The 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 comment
The 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 src
? Under __support/OSUtil
or somewhere else? I was thinking it may not be a bad idea for programs to be able to reuse the conversion.
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