Skip to content
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

glibc: _U and _UL are reserved names #118

Closed
am11 opened this issue May 26, 2019 · 2 comments
Closed

glibc: _U and _UL are reserved names #118

am11 opened this issue May 26, 2019 · 2 comments

Comments

@am11
Copy link
Contributor

am11 commented May 26, 2019

On SmartOS (and probably other Solaris-likes), gcc (v7) throws the following error:

../include/libunwind-common.h:43:41: error: expected identifier or '(' before numeric constant
 # define UNW_PREFIX UNW_PASTE(UNW_PASTE(_U,UNW_TARGET),_)
                                         ^
../include/libunwind-common.h:35:25: note: in definition of macro 'UNW_PASTE2'
 #define UNW_PASTE2(x,y) x##y
                         ^
../include/libunwind-common.h:37:21: note: in expansion of macro 'UNW_PASTE'
 #define UNW_OBJ(fn) UNW_PASTE(UNW_PREFIX, fn)
                     ^~~~~~~~~
../include/libunwind-common.h:36:24: note: in expansion of macro 'UNW_PASTE2'
 #define UNW_PASTE(x,y) UNW_PASTE2(x,y)
                        ^~~~~~~~~~
../include/libunwind-common.h:43:21: note: in expansion of macro 'UNW_PASTE'
 # define UNW_PREFIX UNW_PASTE(UNW_PASTE(_U,UNW_TARGET),_)
                     ^~~~~~~~~
../include/libunwind-common.h:36:24: note: in expansion of macro 'UNW_PASTE2'
 #define UNW_PASTE(x,y) UNW_PASTE2(x,y)
                        ^~~~~~~~~~
../include/libunwind-common.h:43:31: note: in expansion of macro 'UNW_PASTE'
 # define UNW_PREFIX UNW_PASTE(UNW_PASTE(_U,UNW_TARGET),_)
                               ^~~~~~~~~
../include/libunwind-common.h:37:31: note: in expansion of macro 'UNW_PREFIX'
 #define UNW_OBJ(fn) UNW_PASTE(UNW_PREFIX, fn)
                               ^~~~~~~~~~
../include/tdep-x86_64/libunwind_i.h:211:41: note: in expansion of macro 'UNW_OBJ'
 #define tdep_trace                      UNW_OBJ(tdep_trace)
                                         ^~~~~~~
../include/tdep-x86_64/libunwind_i.h:260:12: note: in expansion of macro 'tdep_trace'
 extern int tdep_trace (unw_cursor_t *cursor, void **addresses, int *n);
            ^~~~~~~~~~

According to glibc manual (http://www.gnu.org/software/libc/manual/html_node/Reserved-Names.html):

In addition to the names documented in this manual, reserved names include all external identifiers (global functions and variables) that begin with an underscore (‘_’) and all identifiers regardless of use that begin with either two underscores or an underscore followed by a capital letter are reserved names. This is so that the library and header files can define functions, variables, and macros for internal purposes without risk of conflict with names in user programs.

There are two ways to fix this issue:

  1. rename _U and _UL to something else (will also require changes in tests/check-namespace.sh.in file and other places?).
  2. undefine _U explicitly:
    --- a/include/libunwind-common.h.in
    +++ b/include/libunwind-common.h.in
    @@ -23,6 +23,8 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
     OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
     WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
    
    +#undef _U
    +
     #define UNW_VERSION_MAJOR      @PKG_MAJOR@
     #define UNW_VERSION_MINOR      @PKG_MINOR@
     #define UNW_VERSION_EXTRA      @PKG_EXTRA@

which approach is safe/better? If #1 is non-breaking-ABI, I would go for it (because #2 might have side effects).

@djwatson
Copy link
Member

Unfortunately I think #1 breaks ABI. #2 does seem hacky, but I can't think of anything better.

@am11
Copy link
Contributor Author

am11 commented Jun 12, 2019

Thank you, I think we can close this. Solaris initial changes are merged with undef _U:

#ifdef __sun
// On SmartOS, gcc fails with the following error:
//
// ../include/libunwind-common.h:43:41: error: expected identifier or '(' before numeric constant
// # define UNW_PREFIX UNW_PASTE(UNW_PASTE(_U,UNW_TARGET),_)
// ^
//
// workaround is to undefine _U explicitly.
// see https://github.com/libunwind/libunwind/issues/118 for more details.
//
#undef _U
#endif

@am11 am11 closed this as completed Jun 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants