You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When updating versions of clang we had some compiler errors due to mismatch in declarations between pal.h and system headers (mainly: missing throw specifiers). We can fix these issues by making pal.h match with the system headers.
What is the rationale for having these declaration in pal.h, instead of including system headers?
The PAL is trying to emulate Windows for historic reasons. It made the initial port to Unix easy. Definitions of number of functions on Windows are different from equivalent definitions on Unix. It means that we cannot just include system headers because of the definitions would collide.
Ideally, we would make this Windows emulator go away. A step in this direction would be to define PAL_STDCPP_COMPAT always and make sure that everything still builds and works. It would enable us to include system headers instead of duplicating selected parts of them.
The runtime code on Unix never includes anything from the actual platform, just the pal.h that provides all the functions the runtime depends on. That includes emulated Windows APIs, Windows data types, some extra PAL APIs that don't match windows ones (names starting with PAL_) and some standard C functions like various printf / scanf etc.
The code in PAL implementation also includes the pal.h since it needs to use the Windows data types or define the functions declared in the pal.h. However, the pal.h is not included directly, but rather through palinternal.h that besides other things also handles conflicting function and type names between the Windows and Unix worlds. There are details on that in comments at the beginning of the palinternal.h.
The throw specifier case is kind of special as it needs to be on the function declarations in the pal.h and since these are included from both PAL and runtime, they need to match what the platform uses.
I experimented with this a bit, and came to a better understanding of what type things PAL deals with. 2 examples:
wchar_t is 2-byte utf-16 on Windows, and 4-byte 'unspecified encoding' on Linux. Since strings in managed .NET are UTF-16 at some point you need native functions that work with UTF-16, and those will be distinct, on non-Windows, from system functions that accept wchar_t.
There are some Windows-specific sal annotations on buffers using __in and __out:
I'm confused with the wchar_t problem on Linux. If you have PAL_STDCPP_COMPAT then you dont get the, for example, PAL_fwprintf implementation as its within a #ifndef PAL_STDCPP_COMPAT in pal.h What's the solution here, always substitute fwprintf and other wide char functions on Linux?
#define fwprintf PAL_fwprintf is within #ifndef PAL_STDCPP_COMPAT. PAL_fwprintf is outside #ifndef PAL_STDCPP_COMPAT. You should be able to replace fwprintf with PAL_fwprintf to make things compile.
In file included from /home/scott/github/runtimelab/src/coreclr/nativeresources/resourcestring.cpp:6:
In file included from /home/scott/github/runtimelab/src/coreclr/inc/utilcode.h:14:
In file included from /home/scott/github/runtimelab/src/coreclr/inc/winwrap.h:41:
In file included from /home/scott/github/runtimelab/src/coreclr/nativeresources/../pal/src/include/pal/malloc.hpp:22:
In file included from /home/scott/github/runtimelab/src/coreclr/nativeresources/../pal/src/include/pal/corunix.hpp:23:
In file included from /home/scott/github/runtimelab/src/coreclr/nativeresources/../pal/src/include/pal/palinternal.h:335:
/home/scott/github/runtimelab/src/coreclr/pal/inc/mbusafecrt.h:53:16: error: declaration of 'strcat_s' has a different language linkage
extern errno_t strcat_s( char* ioDest, size_t inDestBufferSize, const char* inSrc );
^
/home/scott/github/runtimelab/src/coreclr/pal/inc/rt/safecrt.h:666:17: note: previous definition is here
errno_t __cdecl strcat_s(char *_Dst, size_t _SizeInBytes, const char *_Src)
^
Comments in mbusafecrt.h indicates its for MacOS but its included unconditionally by palinternal.h. Maybe the right thing is not to include it for Linux ?
/*++
struct PAL_FILE.
Used to mimic the behavior of windows.
fwrite under windows can set the ferror flag,
under BSD fwrite doesn't.
--*/
struct _FILE
{
But that's just _FILE, not actually defining the struct PAL_FILE What am i missing here? At dynamic link of the clrjit time it fails that it is undefined
/home/scott/github/runtimelab/artifacts/bin/coreclr/Linux.x64.Debug/libclrjit_browser_wasm32_x64.so: error: symbol lookup error: undefined symbol: _Z5flogfP9_PAL_FILEPKcz (fatal)
Activity
omajid commentedon Jun 2, 2020
For example, this is the sort of error we ran into with clang 10: #32837
jkotas commentedon Jun 2, 2020
The PAL is trying to emulate Windows for historic reasons. It made the initial port to Unix easy. Definitions of number of functions on Windows are different from equivalent definitions on Unix. It means that we cannot just include system headers because of the definitions would collide.
Ideally, we would make this Windows emulator go away. A step in this direction would be to define
PAL_STDCPP_COMPATalways and make sure that everything still builds and works. It would enable us to include system headers instead of duplicating selected parts of them.janvorli commentedon Jun 2, 2020
The runtime code on Unix never includes anything from the actual platform, just the
pal.hthat provides all the functions the runtime depends on. That includes emulated Windows APIs, Windows data types, some extra PAL APIs that don't match windows ones (names starting withPAL_) and some standard C functions like various printf / scanf etc.The code in PAL implementation also includes the
pal.hsince it needs to use the Windows data types or define the functions declared in thepal.h. However, thepal.his not included directly, but rather throughpalinternal.hthat besides other things also handles conflicting function and type names between the Windows and Unix worlds. There are details on that in comments at the beginning of the palinternal.h.The
throwspecifier case is kind of special as it needs to be on the function declarations in the pal.h and since these are included from both PAL and runtime, they need to match what the platform uses.tmds commentedon Jun 4, 2020
It would be interesting to give this a try to avoid these compiler issues in the future.
tmds commentedon Jun 9, 2020
I experimented with this a bit, and came to a better understanding of what type things PAL deals with. 2 examples:
wchar_tis 2-byte utf-16 on Windows, and 4-byte 'unspecified encoding' on Linux. Since strings in managed .NET are UTF-16 at some point you need native functions that work with UTF-16, and those will be distinct, on non-Windows, from system functions that acceptwchar_t.There are some Windows-specific sal annotations on buffers using
__inand__out:runtime/src/coreclr/src/pal/inc/rt/sal.h
Lines 2658 to 2659 in db70edd
Some Linux headers use
__inand__outas identifiers, so they can't be defined to disappear.All such cases can be death with, though the effort is higher than what I had imagined.
yowl commentedon Dec 30, 2021
I'm confused with the
wchar_tproblem on Linux. If you havePAL_STDCPP_COMPATthen you dont get the, for example,PAL_fwprintfimplementation as its within a#ifndef PAL_STDCPP_COMPATinpal.hWhat's the solution here, always substitutefwprintfand other wide char functions on Linux?jkotas commentedon Dec 31, 2021
#define fwprintf PAL_fwprintfis within#ifndef PAL_STDCPP_COMPAT.PAL_fwprintfis outside#ifndef PAL_STDCPP_COMPAT. You should be able to replacefwprintfwithPAL_fwprintfto make things compile.yowl commentedon Dec 31, 2021
Thanks,
runtime/src/coreclr/pal/src/include/pal/palinternal.h
Line 335 in 07ed923
Uses
size_tbut at its include point that's been defined toDUMMY_size_t, theundefcomes after, and hence:I tried adding to
mbusafecrt.h:which clears this one, but moves to the next:
Comments in
mbusafecrt.hindicates its for MacOS but its included unconditionally bypalinternal.h. Maybe the right thing is not to include it for Linux ?jkotas commentedon Dec 31, 2021
These comments are stale.
I think you can try putting the whole block of the
#define ... DUMMY_....defines in palinternal.h under#ifndef PAL_STDCPP_COMPAT.12 remaining items
jkotas commentedon Jan 3, 2022
Agree.
yowl commentedon Jan 3, 2022
Thanks, do you think all these places where I've included palinternal.h are wrong?:
jkotas commentedon Jan 3, 2022
I think palinternal.h should stay internal to the PAL. It should not be included anywhere else.
janvorli commentedon Jan 3, 2022
Right,
palinternal.his supposed to be used only in the PAL itself.yowl commentedon Jan 3, 2022
Where is the actual definition of
PAL_FILEI can just see the partial declaration in pal.h:And a reference in
cruntime.h:But that's just
_FILE, not actually defining thestruct PAL_FILEWhat am i missing here? At dynamic link of the clrjit time it fails that it is undefinedjkotas commentedon Jan 3, 2022
The partial definition in pal.h that I see is:
struct _FILEis then defined in the PAL implementation.yowl commentedon Jan 3, 2022
Thanks, I'll move that outside of the
#ifFix pal_assert.h for PAL_STDCPP_COMPAT
Fix pal_assert.h when PAL_STDCPP_COMPAT defined (#64631)
janvorli commentedon Jul 12, 2022
It seems that all the questions have been asnwered, closing the issue.