Hi Ching,
The LLVM IR doesn't care about the size of your pointers, and this is
why you have the 'datalayout' explicit on the object file. I don't
know, however, if you can omit the layout definition and leave it for
run time.
If LLVM doesn't allow omitting the layout, it should, as we now have
an use case that needs it. If it does, it should be just a matter of
converting the current IR into EFI bytecode and creating intrinsics to
deal with the run-time variables. You could even benefit from having
different languages (LLVM supports) into EFI bytecode...
> And I am wondering whether this kind of idea is valuable to the LLVM
> community? or are there any other related ideas is more valuable?
I think that an open source compiler to EFI byte code is not only
desirable, but necessary.
cheers,
--renato
Reclaim your digital rights, eliminate DRM, learn more at
http://www.defectivebydesign.org/what_is_drm
_______________________________________________
LLVM Developers mailing list
LLV...@cs.uiuc.edu http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
On 10 March 2010 16:57, 琬菁楊 <ching11...@g2.nctu.edu.tw> wrote:Hi Ching,
> I think the main issue is that EFI C dialect is not ANSI-C compliant: the
> size of pointer is determined at the run-time and therefore the layout of
> the structure is not static. Does LLVM support this model?
The LLVM IR doesn't care about the size of your pointers, and this is
why you have the 'datalayout' explicit on the object file. I don't
know, however, if you can omit the layout definition and leave it for
run time.
If LLVM doesn't allow omitting the layout, it should, as we now have
an use case that needs it. If it does, it should be just a matter of
converting the current IR into EFI bytecode and creating intrinsics to
deal with the run-time variables. You could even benefit from having
different languages (LLVM supports) into EFI bytecode...
The layout for non-packed structures is, in this sense, left for
runtime. The definition, if lacking any alignment attributes, will be
layed out in the backend according to the alignment rules then. The
IR layout definition can be happily cross-platform if you always
access the structures in a type-safe way (using GEP, never castes,
etc).
> If LLVM doesn't allow omitting the layout, it should, as we now have
> an use case that needs it. If it does, it should be just a matter of
> converting the current IR into EFI bytecode and creating intrinsics to
> deal with the run-time variables. You could even benefit from having
> different languages (LLVM supports) into EFI bytecode...
How does EFI describe structures if the pointer size can change? This
shouldn't be a harder problem than C struct -> llvm struct. I assume
the EFI bytecode has some way to describe them. What is it?
(Question is for Ching)
Andrew
EFI describe structures almost like C.
There are EBC instructions that have two immediates: one for 32bits pointers and one for 64bits pointers.
What do you mean by "variable sized pointers"? What does:struct S {void *X; };return for sizeof(struct S); ?It doesn't, at least not for Intel's EBC compiler. They error out on any sizeof that include a pointer. A piece of EBC code can run in either a 32 bit or 64 bit environment, and everything in the compiler either needs to cope with it (by conditionally choosing the size of offsets into structs, for instance) or give up on it and abort. That also means that you cannot compile code that depends on knowing pointer sizes in the preprocessor, etc.
I suspect getting something like this to work would require substantial changes to any existing C frontend, since as a language assumes knowledge of pointer size. On the other hand, it would allow for some neat tricks since it would allow one to compile a significant subset of C code to a pointer neutral intermediary form. Off the top of my head I can think of several potential uses for that, such as PNaCl <http://blog.chromium.org/2010/03/native-client-and-web-portability.html>.
On Fri, Mar 19, 2010 at 3:47 PM, Chris Lattner <clat...@apple.com> wrote:On Mar 19, 2010, at 11:08 AM, 琬菁楊 wrote:Hello Tristan and all,
I have already know that if I want to do this feature(c -> EFI Byte code) for GCC
I should further modify the GCC front end(parser) to solve the problem (the size
of pointer is determined at run time).
I have read a powerpoint about LLVM (http://llvm.org/pubs/2008-10-04-ACAT-LLVM-Intro.pdf)
It is the LLVM-GCC design graph (http://www.im.ntu.edu.tw/~b95030/llvm_gcc.png).
According to the above discussion , LLVM IR doesn't care about the size of pointers.
I am wondering how could LLVM support dynamic pointer size model without modifying
GCC front end??What do you mean by "variable sized pointers"? What does:struct S {void *X; };return for sizeof(struct S); ?
It doesn't, at least not for Intel's EBC compiler. They error out on any sizeof that include a pointer. A piece of EBC code can run in either a 32 bit or 64 bit environment, and everything in the compiler either needs to cope with it (by conditionally choosing the size of offsets into structs, for instance) or give up on it and abort. That also means that you cannot compile code that depends on knowing pointer sizes in the preprocessor, etc.I suspect getting something like this to work would require substantial changes to any existing C frontend, since as a language assumes knowledge of pointer size. On the other hand, it would allow for some neat tricks since it would allow one to compile a significant subset of C code to a pointer neutral intermediary form. Off the top of my head I can think of several potential uses for that, such as PNaCl <http://blog.chromium.org/2010/03/native-client-and-web-portability.html>.Louis
What do you mean by "variable sized pointers"? What does:struct S {void *X; };return for sizeof(struct S); ?
I have surveyed the UEFI spec2.3.
In my opinion, if the EBC VM is running on 32-bit processor, return value is 4
if the EBC VM is running on 64-bit processor, return value is 8
If error out on any sizeof that include a pointer, does it means that no issue about pointer size determined at runtime??
> How does EFI describe structures if the pointer size can change? ThisEFI describe structures almost like C.
> shouldn't be a harder problem than C struct -> llvm struct. I assume
> the EFI bytecode has some way to describe them. What is it?
There are EBC instructions that have two immediates: one for 32bits pointers and one for 64bits pointers.
But it is not an error, otherwise it would be hard to use malloc() like functions.
I don't see why it should be that difficult.
If sizeof becomes an intrinsic that is called at runtime to determine
the pointer size (probably stored in some global or read from a
configuration register), than the problem is solved. If the types'
sizes change too, this intrinsic could accept a parameter (enum?) with
the type of the type.
cheers,
--renato
Reclaim your digital rights, eliminate DRM, learn more at
http://www.defectivebydesign.org/what_is_drm
But it is not an error, otherwise it would be hard to use malloc() like functions.
It would be hard to use malloc *iff* sizeof of a structure that includes a pointer is flagged as an error
by the compiler.
EBC C compilers are clearly non ansi-C conformant.
Tristan.
2010/3/20 Chris Lattner <clat...@apple.com>
Ok, that makes sense. It could be done by generalizing the notions of variably modified types (which are VLAs in C99) to include pointers.On Mar 19, 2010, at 2:40 PM, Louis Gerbarg wrote:
What do you mean by "variable sized pointers"? What does:struct S {void *X; };return for sizeof(struct S); ?It doesn't, at least not for Intel's EBC compiler. They error out on any sizeof that include a pointer. A piece of EBC code can run in either a 32 bit or 64 bit environment, and everything in the compiler either needs to cope with it (by conditionally choosing the size of offsets into structs, for instance) or give up on it and abort. That also means that you cannot compile code that depends on knowing pointer sizes in the preprocessor, etc.
int main()
{
size_t size;
size = fsize3(10); // fsize3 returns 13
return 0;
}
And I found some information with clang about VLA
(http://clang.llvm.org/cxx_compatibility.html#vla)
Does llvm/clang doesn't support sizeof is evaluated at run time??
> Hello Chris,
>
> I have survey the efi specification and ask some question to efi engineer.
> Difference between EFI C and ANSI C is as following:
> 1. void*
> In EFI C, the void* is 4-byte for 32-bit processor and 8-byte for 64-bit processor.
> And it can appears in any where like ANSI C.
> So the main problem is that struct layout like
> struct S{
> void* X;
> };
> is not static.
> 2. no floating support in EFI C
> 3. no C++ support in EFI C
> 4. no assembly support in EFI C, all assembly must convert to C
Ok, all of this is easy except #1.
> I am wondering that does LLVM support model which structure layout is determined at run time??
No.
> If not, do I need to modify the parser in clang to support this feature??
No, please don't. This is something we specifically do not want to support. The issue is not the parser, the issue is that struct field offsets are no longer constant in this model.
-Chris
> If not, do I need to modify the parser in clang to support this feature??No, please don't. This is something we specifically do not want to support. The issue is not the parser, the issue is that struct field offsets are no longer constant in this model.
LLVM may not be a good match for this project, but there's prior art elsewhere; have a look at ANDF.
What about declaring that pointers are always 64 bits, for all
purposes other than final code generation of actual pointer
instructions? Would that solve the problem?
> On Fri, Apr 2, 2010 at 6:17 PM, Chris Lattner <clat...@apple.com> wrote:
>> No, please don't. This is something we specifically do not want to support. The issue is not the parser, the issue is that struct field offsets are no longer constant in this model.
>
> What about declaring that pointers are always 64 bits, for all
> purposes other than final code generation of actual pointer
> instructions? Would that solve the problem?
Yep. That would be a fine approach, and probably conformant to the spec.
-Chris
Yep. That would be a fine approach, and probably conformant to the spec.> What about declaring that pointers are always 64 bits, for all
> purposes other than final code generation of actual pointer
> instructions? Would that solve the problem?
> On Fri, Apr 2, 2010 at 6:17 PM, Chris Lattner <clat...@apple.com> wrote:
>> No, please don't. This is something we specifically do not want to support. The issue is not the parser, the issue is that struct field offsets are no longer constant in this model.
>
> What about declaring that pointers are always 64 bits, for all
> purposes other than final code generation of actual pointer
> instructions? Would that solve the problem?
No, sizeof will report wrong values.
Tristan.
>
> On Apr 3, 2010, at 2:36 PM, Russell Wallace wrote:
>
>> On Fri, Apr 2, 2010 at 6:17 PM, Chris Lattner <clat...@apple.com> wrote:
>>> No, please don't. This is something we specifically do not want to support. The issue is not the parser, the issue is that struct field offsets are no longer constant in this model.
>>
>> What about declaring that pointers are always 64 bits, for all
>> purposes other than final code generation of actual pointer
>> instructions? Would that solve the problem?
>
> No, sizeof will report wrong values.
Which won't matter (as long as sizeof is consistent), because EFI is a closed system.
-Chris
Which won't matter (as long as sizeof is consistent), because EFI is a closed system.
> I have survey the efi specification and ask some question to efi engineer.Ok, all of this is easy except #1.
> Difference between EFI C and ANSI C is as following:
> 1. void*
> In EFI C, the void* is 4-byte for 32-bit processor and 8-byte for 64-bit processor.
> And it can appears in any where like ANSI C.
> So the main problem is that struct layout like
> struct S{
> void* X;
> };
> is not static.
> 2. no floating support in EFI C
> 3. no C++ support in EFI C
> 4. no assembly support in EFI C, all assembly must convert to C
No.
> I am wondering that does LLVM support model which structure layout is determined at run time??
No, please don't. This is something we specifically do not want to support. The issue is not the parser, the issue is that struct field offsets are no longer constant in this model.
> If not, do I need to modify the parser in clang to support this feature??
>
> On Apr 6, 2010, at 1:10 AM, Tristan Gingold wrote:
>
>>
>> On Apr 3, 2010, at 2:36 PM, Russell Wallace wrote:
>>
>>> On Fri, Apr 2, 2010 at 6:17 PM, Chris Lattner <clat...@apple.com> wrote:
>>>> No, please don't. This is something we specifically do not want to support. The issue is not the parser, the issue is that struct field offsets are no longer constant in this model.
>>>
>>> What about declaring that pointers are always 64 bits, for all
>>> purposes other than final code generation of actual pointer
>>> instructions? Would that solve the problem?
>>
>> No, sizeof will report wrong values.
>
> Which won't matter (as long as sizeof is consistent), because EFI is a closed system.
No, EFI is not that closed: boot loaders interface with EFI.
Don't forget that EBC code can call native functions. If sizeof or fields offsets mismatch I fear that the
program won't work.
Tristan.
No, sizeof will report wrong values.> What about declaring that pointers are always 64 bits, for all
> purposes other than final code generation of actual pointer
> instructions? Would that solve the problem?