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