001-eliminate-protected-visibility-data-in-libc.so-with-.patch 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. From: Rich Felker <[email protected]>
  2. Date: Tue, 29 Sep 2015 02:44:05 +0000
  3. Subject: [PATCH] eliminate protected-visibility data in libc.so with vis.h
  4. preinclude
  5. some newer binutils versions print scary warnings about protected data
  6. because most gcc versions fail to produce the right address
  7. references/relocations for such data that might be subject to copy
  8. relocations. originally vis.h explicitly assigned default visibility
  9. to all public data symbols to avoid this issue, but commit
  10. b8dda24fe1caa901a99580f7a52defb95aedb67c removed this treatment for
  11. stdin/out/err to work around a gcc 3.x bug, and since they don't
  12. actually need it (because taking their addresses is not valid C).
  13. instead, a check for the gcc 3.x bug is added to the configure check
  14. for vis.h preinclude support; this feature will simply be disabled
  15. when using a buggy version of gcc.
  16. ---
  17. --- a/configure
  18. +++ b/configure
  19. @@ -476,10 +476,18 @@ if test "x$visibility" = xauto ; then
  20. # - the -include option
  21. # - the attributes/pragmas used in vis.h
  22. # - linking code that takes the address of protected symbols
  23. +# - gcc 3.x bug that wrongly claims declarations mismatch
  24. printf "checking whether global visibility preinclude works... "
  25. -echo 'int (*fp)(void);' > "$tmpc"
  26. -echo 'int foo(void) { }' >> "$tmpc"
  27. -echo 'int bar(void) { fp = foo; return foo(); }' >> "$tmpc"
  28. +cat > "$tmpc" <<EOF
  29. +__attribute__((__visibility__("default")))
  30. +extern struct a *const x;
  31. +typedef struct a b;
  32. +extern b *const x;
  33. +b *const x;
  34. +int (*fp)(void);
  35. +int foo(void) { }
  36. +int bar(void) { fp = foo; return foo(); }
  37. +EOF
  38. if $CC $CFLAGS_C99FSE $CPPFLAGS $CFLAGS \
  39. -DSHARED -fPIC -I./src/internal -include vis.h \
  40. -nostdlib -shared -Wl,-Bsymbolic-functions \
  41. --- a/src/internal/vis.h
  42. +++ b/src/internal/vis.h
  43. @@ -12,6 +12,9 @@
  44. * exported data symbols. */
  45. __attribute__((__visibility__("default")))
  46. +extern struct _IO_FILE *const stdin, *const stdout, *const stderr;
  47. +
  48. +__attribute__((__visibility__("default")))
  49. extern int optind, opterr, optopt, optreset, __optreset, getdate_err, h_errno, daylight, __daylight, signgam, __signgam;
  50. __attribute__((__visibility__("default")))