On 08/06/14 19:05, Andrew Fish wrote: > LegacyBiosInt86() sets a pointer to 0 and dereferences it. From a C > standard point of view this is considered undefined behavior. The clang > optimizer emits a trap instruction and throws all the code after the > reference away. The trap is replaced via a compiler flag to be a > function that does not exist, and thus this is why we get a link failure. > > The optimizer needs to avoid optimizations on a volatile variable, so > the only safe way to write to zero in C is to use a volatile variable. > See http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html > > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Anderw Fish <[email protected] <mailto:[email protected]>> > > ~/work/src/edk2(master)>git diff > IntelFrameworkModulePkg/Csm/LegacyBiosDxe/Thunk.c > *diff --git a/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/Thunk.c > b/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/Thunk.c* > *index 3d9a8b9..a5d2f14 100644* > *--- a/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/Thunk.c* > *+++ b/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/Thunk.c* > @@ -57,7 +57,7 @@ LegacyBiosInt86 ( > IN EFI_IA32_REGISTER_SET *Regs > ) > { > - UINT32 *VectorBase; > + volatile UINT32 *VectorBase; > > > > Regs->X.Flags.Reserved1 = 1; > Regs->X.Flags.Reserved2 = 0; > > > Thanks, > > Andrew Fish > > PS I finally got around to testing clang out on OVFM. Right now I’m in a > “World of Hurt”(TM) trying to get > UefiCpuPkg/Library/CpuExceptionHandlerLib to work. It seems that > CpuExceptionHandlerLib assembly has a lot of X64 relocations that the > Xcode linker does not support.
(1) Patch Reviewed-by: Laszlo Ersek <[email protected]> ( (2) Since we're talking volatile, I can't avoid calling attention (again) to SVN r13878. That patch introduces undefined behavior: 6.7.3 Type qualifiers 5 If an attempt is made to modify an object defined with a const-qualified type through use of an lvalue with non-const-qualified type, the behavior is undefined. If an attempt is made to refer to an object defined with a volatile-qualified type through use of an lvalue with non-volatile-qualified type, the behavior is undefined. This is the prototype of ZeroMem(): VOID * EFIAPI ZeroMem ( OUT VOID *Buffer, IN UINTN Length ); Note the absence of volatile. "Request" and "Response" are defined with a volatile-qualified type. ) Laszlo ------------------------------------------------------------------------------ Infragistics Professional Build stunning WinForms apps today! Reboot your WinForms applications with our WinForms controls. Build a bridge from your legacy apps to the future. http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk _______________________________________________ edk2-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/edk2-devel
