{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/coreclr/issues/1091","labels_url":"https://api.github.com/repos/dotnet/coreclr/issues/1091/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/coreclr/issues/1091/comments","events_url":"https://api.github.com/repos/dotnet/coreclr/issues/1091/events","html_url":"https://github.com/dotnet/coreclr/issues/1091","id":84812969,"number":1091,"title":"palinternal.h breaks \"errno\": src/pal/src/include/pal/thread.hpp:498:13: error: use of undeclared identifier 'errno'","user":{"login":"saper","id":248374,"avatar_url":"https://avatars.githubusercontent.com/u/248374?v=3","gravatar_id":"","url":"https://api.github.com/users/saper","html_url":"https://github.com/saper","followers_url":"https://api.github.com/users/saper/followers","following_url":"https://api.github.com/users/saper/following{/other_user}","gists_url":"https://api.github.com/users/saper/gists{/gist_id}","starred_url":"https://api.github.com/users/saper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saper/subscriptions","organizations_url":"https://api.github.com/users/saper/orgs","repos_url":"https://api.github.com/users/saper/repos","events_url":"https://api.github.com/users/saper/events{/privacy}","received_events_url":"https://api.github.com/users/saper/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":19,"created_at":"2015-06-03T23:18:32Z","updated_at":"2015-10-08T08:55:33Z","closed_at":null,"body":"I was [unable to compile CoreCLR on FreeBSD](https://github.com/dotnet/coreclr/issues/1044#issuecomment-107916239), due to `errno` being apparently undefined at the point where it's needed in `src/pal/src/include/thread.hpp`. ([full log](https://gist.github.com/saper/eafc21d80b753511270d)).\r\n\r\nThe problem might have been uncovered (but not caused) by f1b2b7d934339b0def5a96f111ea954974156ff8, which (re)introduced the use of system `errno` instead of using some own implementation.\r\n\r\nThe problem is that `palinternal.h` is a clever trick that does not handle some system headers fully.\r\nIt is worth to read https://github.com/dotnet/coreclr/blob/master/src/pal/src/include/pal/palinternal.h#L14-L136 before proceeding :)\r\n\r\nWhat happens is this:\r\n\r\n- `src/exception/seh.cpp` includes `<typeinfo>` and then `\"pal/thread.hpp\"`\r\n- on my system `<typeinfo>` includes `<errno.h>`\r\n- `<palinternal.h>` does its funny tricks and together with `<pal.h>` try to redefine `errno`. \r\n- What happens in the end is that `errno` stays undefined once the `corunix.hpp` is processed.\r\n- Subsequent `#include <errno.h>` in the `thread.hpp` DOES NOT help, because `<errno.h>` was already included and the header guard (in my case `_SYS_ERRNO_H_`) is already defined\r\n- This way we never get original system macro definition of `errno` back.\r\n- This problem does not occur in the other files because at the point `palinternal.h` gets used `<errno.h>` has not yet been included by any other file.\r\n\r\nSo there needs to be a warning in the 'palinternal.h' file that explains the problem - \r\nusing header files of the undef'd identifiers is probably a no-no.\r\n\r\nWhen moving some function from category `A.2` (as described in `palinternal.h`) to category `A.1` \r\nit needs to be carefully checked if everything gets defined again.\r\n\r\nNot sure where the bug is, maybe `#undef errno` and friends should go away, maybe `errno` should not be redefined in `pal.h`... etc. etc.\r\n\r\nAnyway, my workaround was to include `<typeinfo>` *after* `\"pal/thread.hpp\"` in the `seh.cpp`\r\nand the CoreCLR got compiled; but that is certainly not a solution.\r\n\r\nThis problem is not very FreeBSD specific, any use of some system header before `palinternal.h` gets included may create such problems, or worse, hidden bugs.\r\n\r\n(mentioning https://github.com/dotnet/coreclr/issues/1010)\r\n\r\nThanks @josteink @jasonwilliams200OK for assisting me to get this sorted out.\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/dotnet/coreclr/issues/comments/146462588","html_url":"https://github.com/dotnet/coreclr/issues/1091#issuecomment-146462588","issue_url":"https://api.github.com/repos/dotnet/coreclr/issues/1091","id":146462588,"user":{"login":"josteink","id":411338,"avatar_url":"https://avatars.githubusercontent.com/u/411338?v=3","gravatar_id":"","url":"https://api.github.com/users/josteink","html_url":"https://github.com/josteink","followers_url":"https://api.github.com/users/josteink/followers","following_url":"https://api.github.com/users/josteink/following{/other_user}","gists_url":"https://api.github.com/users/josteink/gists{/gist_id}","starred_url":"https://api.github.com/users/josteink/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josteink/subscriptions","organizations_url":"https://api.github.com/users/josteink/orgs","repos_url":"https://api.github.com/users/josteink/repos","events_url":"https://api.github.com/users/josteink/events{/privacy}","received_events_url":"https://api.github.com/users/josteink/received_events","type":"User","site_admin":false},"created_at":"2015-10-08T08:55:33Z","updated_at":"2015-10-08T08:55:33Z","body":"Fair enough. That's much more targeted and does sound better. I'll take your word for it :)"}}