1 diff -aur gcc-3.4.0orig/gcc/c-common.c gcc-3.4.0/gcc/c-common.c
2 --- gcc-3.4.0orig/gcc/c-common.c 2004-03-19 01:32:59.000000000 +0000
3 +++ gcc-3.4.0/gcc/c-common.c 2004-05-10 21:05:33.000000000 +0100
5 handle_deprecated_attribute },
6 { "vector_size", 1, 1, false, true, false,
7 handle_vector_size_attribute },
8 - { "visibility", 1, 1, true, false, false,
9 + { "visibility", 1, 1, false, false, false,
10 handle_visibility_attribute },
11 { "tls_model", 1, 1, true, false, false,
12 handle_tls_model_attribute },
13 @@ -4886,7 +4886,16 @@
17 - if (decl_function_context (decl) != 0 || ! TREE_PUBLIC (decl))
20 + if (TREE_CODE (*node) != RECORD_TYPE && TREE_CODE (*node) != UNION_TYPE)
22 + warning ("`%s' attribute ignored on non-class types",
23 + IDENTIFIER_POINTER (name));
27 + else if (decl_function_context (decl) != 0 || ! TREE_PUBLIC (decl))
29 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
31 @@ -4897,6 +4906,14 @@
32 error ("visibility arg not a string");
36 + /* If this is a type, set the visibility on the type decl. */
39 + decl = TYPE_NAME (decl);
44 if (strcmp (TREE_STRING_POINTER (id), "default") == 0)
45 DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
46 @@ -4908,6 +4925,14 @@
47 DECL_VISIBILITY (decl) = VISIBILITY_PROTECTED;
49 error ("visibility arg must be one of \"default\", \"hidden\", \"protected\" or \"internal\"");
50 + DECL_VISIBILITYSPECIFIED (decl) = 1;
52 + /* For decls only, go ahead and attach the attribute to the node as well.
53 + This is needed so we can determine whether we have VISIBILITY_DEFAULT
54 + because the visibility was not specified, or because it was explicitly
55 + overridden from the class visibility. */
57 + *no_add_attrs = false;
62 diff -aur gcc-3.4.0orig/gcc/c-decl.c gcc-3.4.0/gcc/c-decl.c
63 --- gcc-3.4.0orig/gcc/c-decl.c 2004-03-22 17:58:18.000000000 +0000
64 +++ gcc-3.4.0/gcc/c-decl.c 2004-05-10 15:16:27.000000000 +0100
69 - /* All decls must agree on a non-default visibility. */
70 - if (DECL_VISIBILITY (newdecl) != VISIBILITY_DEFAULT
71 - && DECL_VISIBILITY (olddecl) != VISIBILITY_DEFAULT
72 + /* All decls must agree on a visibility. */
73 + if (DECL_VISIBILITYSPECIFIED (newdecl) && DECL_VISIBILITYSPECIFIED (olddecl)
74 && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl))
76 warning ("%Jredeclaration of '%D' with different visibility "
77 @@ -1361,9 +1360,12 @@
78 Currently, it can only be defined in the prototype. */
79 COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
81 - /* If either declaration has a nondefault visibility, use it. */
82 - if (DECL_VISIBILITY (olddecl) != VISIBILITY_DEFAULT)
83 - DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
84 + /* Use visibility of whichever declaration had it specified */
85 + if (DECL_VISIBILITYSPECIFIED (olddecl))
87 + DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
88 + DECL_VISIBILITYSPECIFIED (newdecl) = 1;
91 if (TREE_CODE (newdecl) == FUNCTION_DECL)
94 diff -aur gcc-3.4.0orig/gcc/common.opt gcc-3.4.0/gcc/common.opt
95 --- gcc-3.4.0orig/gcc/common.opt 2004-02-18 00:09:04.000000000 +0000
96 +++ gcc-3.4.0/gcc/common.opt 2004-05-09 08:10:50.000000000 +0100
99 Add extra commentary to assembler output
102 +Common Joined RejectNegative
103 +-fvisibility=[default|internal|hidden|protected] Set the default symbol visibility
108 Use expression value profiles in optimizations
110 diff -aur gcc-3.4.0orig/gcc/c.opt gcc-3.4.0/gcc/c.opt
111 --- gcc-3.4.0orig/gcc/c.opt 2004-02-18 00:09:03.000000000 +0000
112 +++ gcc-3.4.0/gcc/c.opt 2004-05-09 08:10:50.000000000 +0100
115 Use __cxa_atexit to register destructors
117 +fvisibility-inlines-hidden
119 +Marks all inlined methods as having hidden visibility
123 Discard unused virtual functions
124 diff -aur gcc-3.4.0orig/gcc/c-opts.c gcc-3.4.0/gcc/c-opts.c
125 --- gcc-3.4.0orig/gcc/c-opts.c 2004-02-18 00:09:03.000000000 +0000
126 +++ gcc-3.4.0/gcc/c-opts.c 2004-05-09 08:10:50.000000000 +0100
128 case OPT_fuse_cxa_atexit:
129 flag_use_cxa_atexit = value;
132 + case OPT_fvisibility_inlines_hidden:
133 + visibility_options.inlineshidden = value;
139 diff -aur gcc-3.4.0orig/gcc/cp/class.c gcc-3.4.0/gcc/cp/class.c
140 --- gcc-3.4.0orig/gcc/cp/class.c 2004-03-09 07:27:23.000000000 +0000
141 +++ gcc-3.4.0/gcc/cp/class.c 2004-05-10 21:06:50.000000000 +0100
143 DECL_ALIGN (decl) = MAX (TYPE_ALIGN (double_type_node),
146 + /* The vtable's visibility is the class visibility. There is no way
147 + to override the visibility for just the vtable. */
148 + DECL_VISIBILITY (decl) = CLASSTYPE_VISIBILITY (class_type);
149 + DECL_VISIBILITYSPECIFIED (decl) = CLASSTYPE_VISIBILITYSPECIFIED (class_type);
150 import_export_vtable (decl, class_type, 0);
153 @@ -2971,7 +2975,25 @@
156 if (TREE_CODE (x) == CONST_DECL || TREE_CODE (x) == VAR_DECL)
159 + /* Apply the class's visibility attribute to static members
160 + which do not have a visibility attribute. */
161 + if (! lookup_attribute ("visibility", DECL_ATTRIBUTES (x)))
163 + if (visibility_options.inlineshidden && DECL_INLINE (x))
165 + DECL_VISIBILITY (x) = VISIBILITY_HIDDEN;
166 + DECL_VISIBILITYSPECIFIED (x) = 1;
170 + DECL_VISIBILITY (x) = CLASSTYPE_VISIBILITY (current_class_type);
171 + DECL_VISIBILITYSPECIFIED (x) = CLASSTYPE_VISIBILITYSPECIFIED (current_class_type);
178 /* Now it can only be a FIELD_DECL. */
180 @@ -3708,6 +3730,22 @@
181 check_for_override (x, t);
182 if (DECL_PURE_VIRTUAL_P (x) && ! DECL_VINDEX (x))
183 cp_error_at ("initializer specified for non-virtual method `%D'", x);
185 + /* Apply the class's visibility attribute to methods which do
186 + not have a visibility attribute. */
187 + if (! lookup_attribute ("visibility", DECL_ATTRIBUTES (x)))
189 + if (visibility_options.inlineshidden && DECL_INLINE (x))
191 + DECL_VISIBILITY (x) = VISIBILITY_HIDDEN;
192 + DECL_VISIBILITYSPECIFIED (x) = 1;
196 + DECL_VISIBILITY (x) = CLASSTYPE_VISIBILITY (current_class_type);
197 + DECL_VISIBILITYSPECIFIED (x) = CLASSTYPE_VISIBILITYSPECIFIED (current_class_type);
201 /* The name of the field is the original field name
202 Save this in auxiliary field for later overloading. */
203 @@ -7830,3 +7868,4 @@
204 *vid->last_init = build_tree_list (NULL_TREE, init);
205 vid->last_init = &TREE_CHAIN (*vid->last_init);
209 diff -aur gcc-3.4.0orig/gcc/cp/cp-tree.h gcc-3.4.0/gcc/cp/cp-tree.h
210 --- gcc-3.4.0orig/gcc/cp/cp-tree.h 2004-03-20 00:13:08.000000000 +0000
211 +++ gcc-3.4.0/gcc/cp/cp-tree.h 2004-05-10 20:56:56.000000000 +0100
212 @@ -1008,7 +1008,12 @@
213 #define PUBLICLY_UNIQUELY_DERIVED_P(PARENT, TYPE) \
214 (lookup_base ((TYPE), (PARENT), ba_not_special | ba_quiet, NULL) \
218 +/* Gives the visibility specification for a class type. */
219 +#define CLASSTYPE_VISIBILITY(TYPE) DECL_VISIBILITY (TYPE_NAME (TYPE))
220 +#define CLASSTYPE_VISIBILITYSPECIFIED(TYPE) DECL_VISIBILITYSPECIFIED (TYPE_NAME (TYPE))
223 /* This is a few header flags for 'struct lang_type'. Actually,
224 all but the first are used only for lang_type_class; they
225 are put in this structure to save space. */
227 diff -aur gcc-3.4.0orig/gcc/cp/decl.c gcc-3.4.0/gcc/cp/decl.c
228 --- gcc-3.4.0orig/gcc/cp/decl.c 2004-04-01 21:47:21.000000000 +0100
229 +++ gcc-3.4.0/gcc/cp/decl.c 2004-05-28 21:16:11.000000000 +0100
230 @@ -1869,17 +1869,34 @@
231 DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
232 COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
234 - /* If either declaration has a nondefault visibility, use it. */
235 - if (DECL_VISIBILITY (olddecl) != VISIBILITY_DEFAULT)
236 + /* Warn about conflicting visibility specifications. */
237 + if (DECL_VISIBILITYSPECIFIED (olddecl) && DECL_VISIBILITYSPECIFIED (newdecl)
238 + && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl))
240 + warning ("%J'%D': visibility attribute ignored because it",
242 + warning ("%Jconflicts with previous declaration here", olddecl);
244 + /* Choose the declaration which specified visibility. */
245 + if (DECL_VISIBILITYSPECIFIED (olddecl))
247 - if (DECL_VISIBILITY (newdecl) != VISIBILITY_DEFAULT
248 - && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl))
250 - warning ("%J'%D': visibility attribute ignored because it",
252 - warning ("%Jconflicts with previous declaration here", olddecl);
254 DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
255 + DECL_VISIBILITYSPECIFIED (newdecl) = 1;
257 + /* If it's a definition of a global operator new or operator
258 + delete, it must be default visibility. */
259 + if (NEW_DELETE_OPNAME_P (DECL_NAME (newdecl)) && DECL_INITIAL (newdecl) != NULL_TREE)
261 + if (!DECL_FUNCTION_MEMBER_P (newdecl) && VISIBILITY_DEFAULT != DECL_VISIBILITY (newdecl))
263 + warning ("%J`%D': ignoring non-default symbol",
265 + warning ("%Jvisibility on global operator new or delete", newdecl);
266 + DECL_VISIBILITY (olddecl) = VISIBILITY_DEFAULT;
267 + DECL_VISIBILITYSPECIFIED (olddecl) = 1;
268 + DECL_VISIBILITY (newdecl) = VISIBILITY_DEFAULT;
269 + DECL_VISIBILITYSPECIFIED (newdecl) = 1;
273 if (TREE_CODE (newdecl) == FUNCTION_DECL)
275 diff -aur gcc-3.4.0orig/gcc/cp/method.c gcc-3.4.0/gcc/cp/method.c
276 --- gcc-3.4.0orig/gcc/cp/method.c 2004-04-08 23:15:58.000000000 +0100
277 +++ gcc-3.4.0/gcc/cp/method.c 2004-05-09 08:10:52.000000000 +0100
280 TREE_PUBLIC (thunk_fndecl) = TREE_PUBLIC (function);
281 DECL_VISIBILITY (thunk_fndecl) = DECL_VISIBILITY (function);
282 + DECL_VISIBILITYSPECIFIED (thunk_fndecl) = DECL_VISIBILITYSPECIFIED (function);
284 if (flag_syntax_only)
287 diff -aur gcc-3.4.0orig/gcc/cp/optimize.c gcc-3.4.0/gcc/cp/optimize.c
288 --- gcc-3.4.0orig/gcc/cp/optimize.c 2004-02-08 01:52:50.000000000 +0000
289 +++ gcc-3.4.0/gcc/cp/optimize.c 2004-05-09 08:10:52.000000000 +0100
291 DECL_NOT_REALLY_EXTERN (clone) = DECL_NOT_REALLY_EXTERN (fn);
292 TREE_PUBLIC (clone) = TREE_PUBLIC (fn);
293 DECL_VISIBILITY (clone) = DECL_VISIBILITY (fn);
294 + DECL_VISIBILITYSPECIFIED (clone) = DECL_VISIBILITYSPECIFIED (fn);
296 /* Adjust the parameter names and locations. */
297 parm = DECL_ARGUMENTS (fn);
299 diff -aur gcc-3.4.0orig/gcc/cp/rtti.c gcc-3.4.0/gcc/cp/rtti.c
300 --- gcc-3.4.0orig/gcc/cp/rtti.c 2004-03-08 23:00:26.000000000 +0000
301 +++ gcc-3.4.0/gcc/cp/rtti.c 2004-05-10 21:09:21.000000000 +0100
303 pushdecl_top_level_and_finish (d, NULL_TREE);
305 if (CLASS_TYPE_P (type))
306 - CLASSTYPE_TYPEINFO_VAR (TYPE_MAIN_VARIANT (type)) = d;
308 + CLASSTYPE_TYPEINFO_VAR (TYPE_MAIN_VARIANT (type)) = d;
309 + DECL_VISIBILITY (d) = CLASSTYPE_VISIBILITY (type);
310 + DECL_VISIBILITYSPECIFIED (d) = CLASSTYPE_VISIBILITYSPECIFIED (type);
313 /* Remember the type it is for. */
314 TREE_TYPE (name) = type;
316 TREE_STATIC (name_decl) = 1;
317 DECL_EXTERNAL (name_decl) = 0;
318 TREE_PUBLIC (name_decl) = 1;
319 + if (CLASS_TYPE_P (target))
321 + DECL_VISIBILITY (name_decl) = CLASSTYPE_VISIBILITY (target);
322 + DECL_VISIBILITYSPECIFIED (name_decl) = CLASSTYPE_VISIBILITYSPECIFIED (target);
324 import_export_tinfo (name_decl, target, typeinfo_in_lib_p (target));
325 /* External name of the string containing the type's name has a
328 diff -aur gcc-3.4.0orig/gcc/c-pragma.c gcc-3.4.0/gcc/c-pragma.c
329 --- gcc-3.4.0orig/gcc/c-pragma.c 2004-01-23 23:35:53.000000000 +0000
330 +++ gcc-3.4.0/gcc/c-pragma.c 2004-05-09 08:10:52.000000000 +0100
336 +#ifdef HANDLE_PRAGMA_VISIBILITY
337 +static void handle_pragma_visibility (cpp_reader *);
339 +/* Sets the default visibility for symbols to something other than that
340 + specified on the command line. */
342 +handle_pragma_visibility (cpp_reader *dummy ATTRIBUTE_UNUSED)
343 +{ /* Form is #pragma GCC visibility push(hidden)|pop */
344 + static int visstack [16], visidx;
346 + enum cpp_ttype token;
347 + enum { bad, push, pop } action = bad;
349 + token = c_lex (&x);
350 + if (token == CPP_NAME)
352 + const char *op = IDENTIFIER_POINTER (x);
353 + if (!strcmp (op, "push"))
355 + else if (!strcmp (op, "pop"))
359 + GCC_BAD ("#pragma GCC visibility must be followed by push or pop");
366 + GCC_BAD ("No matching push for '#pragma GCC visibility pop'");
370 + default_visibility = visstack[--visidx];
371 + visibility_options.inpragma = (visidx>0);
376 + if (c_lex (&x) != CPP_OPEN_PAREN)
377 + GCC_BAD ("missing '(' after '#pragma GCC visibility push' - ignored");
378 + token = c_lex (&x);
379 + if (token != CPP_NAME)
381 + GCC_BAD ("malformed #pragma GCC visibility push");
383 + else if (visidx >= 16)
385 + GCC_BAD ("No more than sixteen #pragma GCC visibility pushes allowed at once");
389 + const char *str = IDENTIFIER_POINTER (x);
390 + visstack[visidx++] = default_visibility;
391 + if (!strcmp (str, "default"))
392 + default_visibility = VISIBILITY_DEFAULT;
393 + else if (!strcmp (str, "internal"))
394 + default_visibility = VISIBILITY_INTERNAL;
395 + else if (!strcmp (str, "hidden"))
396 + default_visibility = VISIBILITY_HIDDEN;
397 + else if (!strcmp (str, "protected"))
398 + default_visibility = VISIBILITY_PROTECTED;
401 + GCC_BAD ("#pragma GCC visibility push() must specify default, internal, hidden or protected");
403 + visibility_options.inpragma = 1;
405 + if (c_lex (&x) != CPP_CLOSE_PAREN)
406 + GCC_BAD ("missing '(' after '#pragma GCC visibility push' - ignored");
409 + if (c_lex (&x) != CPP_EOF)
410 + warning ("junk at end of '#pragma GCC visibility'");
415 /* Front-end wrapper for pragma registration to avoid dragging
416 cpplib.h in almost everywhere. */
419 #ifdef HANDLE_PRAGMA_EXTERN_PREFIX
420 c_register_pragma (0, "extern_prefix", handle_pragma_extern_prefix);
422 +#ifdef HANDLE_PRAGMA_VISIBILITY
423 + c_register_pragma ("GCC", "visibility", handle_pragma_visibility);
426 #ifdef REGISTER_TARGET_PRAGMAS
427 REGISTER_TARGET_PRAGMAS ();
428 diff -aur gcc-3.4.0orig/gcc/c-pragma.h gcc-3.4.0/gcc/c-pragma.h
429 --- gcc-3.4.0orig/gcc/c-pragma.h 2004-01-31 06:18:05.000000000 +0000
430 +++ gcc-3.4.0/gcc/c-pragma.h 2004-05-09 08:10:53.000000000 +0100
432 #define HANDLE_PRAGMA_PACK 1
433 #endif /* HANDLE_PRAGMA_PACK_PUSH_POP */
435 +/* It's safe to always leave visibility pragma enabled as if
436 + visibility is not supported on the host OS platform the
437 + statements are ignored. */
438 +#define HANDLE_PRAGMA_VISIBILITY 1
440 extern void init_pragma (void);
442 /* Front-end wrapper for pragma registration to avoid dragging
445 diff -aur gcc-3.4.0orig/gcc/doc/invoke.texi gcc-3.4.0/gcc/doc/invoke.texi
446 --- gcc-3.4.0orig/gcc/doc/invoke.texi 2004-04-19 00:05:36.000000000 +0100
447 +++ gcc-3.4.0/gcc/doc/invoke.texi 2004-05-28 21:29:36.000000000 +0100
449 -fno-optional-diags -fpermissive @gol
450 -frepo -fno-rtti -fstats -ftemplate-depth-@var{n} @gol
451 -fuse-cxa-atexit -fno-weak -nostdinc++ @gol
452 --fno-default-inline -Wabi -Wctor-dtor-privacy @gol
453 +-fno-default-inline -fvisibility-inlines-hidden @gol
454 +-Wabi -Wctor-dtor-privacy @gol
455 -Wnon-virtual-dtor -Wreorder @gol
456 -Weffc++ -Wno-deprecated @gol
457 -Wno-non-template-friend -Wold-style-cast @gol
459 -fargument-alias -fargument-noalias @gol
460 -fargument-noalias-global -fleading-underscore @gol
461 -ftls-model=@var{model} @gol
462 --ftrapv -fwrapv -fbounds-check}
463 +-ftrapv -fwrapv -fbounds-check @gol
468 @@ -1433,6 +1435,20 @@
469 destructors, but will only work if your C library supports
472 +@item -fvisibility-inlines-hidden
473 +@opindex fvisibility-inlines-hidden
474 +Causes all inlined methods to be marked with
475 +@code{__attribute__ ((visibility ("hidden")))} so that they do not
476 +appear in the export table of a DSO and do not require a PLT indirection
477 +when used within the DSO. Enabling this option can have a dramatic effect
478 +on load and link times of a DSO as it massively reduces the size of the
479 +dynamic export table when the library makes heavy use of templates. While
480 +it can cause bloating through duplication of code within each DSO where
481 +it is used, often the wastage is less than the considerable space occupied
482 +by a long symbol name in the export table which is typical when using
483 +templates and namespaces. For even more savings, combine with the
484 +@code{-fvisibility=hidden} switch.
488 Do not use weak symbol support, even if it is provided by the linker.
489 @@ -11198,6 +11214,54 @@
491 The default without @option{-fpic} is @code{initial-exec}; with
492 @option{-fpic} the default is @code{global-dynamic}.
494 +@item -fvisibility=@var{default|internal|hidden|protected}
495 +@opindex fvisibility
496 +Set the default ELF image symbol visibility to the specified option - all
497 +symbols will be marked with this unless overrided within the code.
498 +Using this feature can very substantially improve linking and
499 +load times of shared object libraries, produce more optimised
500 +code, provide near-perfect API export and prevent symbol clashes.
501 +It is @strong{strongly} recommended that you use this in any shared objects
504 +Despite the nomenclature, @code{default} always means public ie;
505 +available to be linked against from outside the shared object.
506 +@code{protected} and @code{internal} are pretty useless in real-world
507 +usage so the only other commonly used option will be @code{hidden}.
508 +The default if -fvisibility isn't specified is @code{default} ie; make every
509 +symbol public - this causes the same behaviour as previous versions of
512 +A good explanation of the benefits offered by ensuring ELF
513 +symbols have the correct visibility is given by ``How To Write
514 +Shared Libraries'' by Ulrich Drepper (which can be found at
515 +@w{@uref{http://people.redhat.com/~drepper/}}) - however a superior
516 +solution made possible by this option to marking things hidden when
517 +the default is public is to make the default hidden and mark things
518 +public. This is the norm with DLL's on Windows and with @option{-fvisibility=hidden}
519 +and @code{__attribute__ ((visibility("default")))} instead of
520 +@code{__declspec(dllexport)} you get almost identical semantics with
521 +identical syntax. This is a great boon to those working with
522 +cross-platform projects.
524 +For those adding visibility support to existing code, you may find
525 +@samp{#pragma GCC visibility} of use. This works by you enclosing
526 +the declarations you wish to set visibility for with (for example)
527 +@samp{#pragma GCC visibility push(hidden)} and
528 +@samp{#pragma GCC visibility pop}. These can be nested up to sixteen
529 +times. Bear in mind that symbol visibility should be viewed @strong{as
530 +part of the API interface contract} and thus all new code should
531 +always specify visibility when it is not the default ie; declarations
532 +only for use within the local DSO should @strong{always} be marked explicitly
533 +as hidden as so to avoid PLT indirection overheads - making this
534 +abundantly clear also aids readability and self-documentation of the code.
535 +Note that due to ISO C++ specification requirements, operator new and
536 +operator delete must always be of default visibility.
538 +An overview of these techniques, their benefits and how to use them
539 +is at @w{@uref{http://www.nedprod.com/programs/gccvisibility.html}}.
545 diff -aur gcc-3.4.0orig/gcc/flags.h gcc-3.4.0/gcc/flags.h
546 --- gcc-3.4.0orig/gcc/flags.h 2004-02-18 00:09:04.000000000 +0000
547 +++ gcc-3.4.0/gcc/flags.h 2004-05-09 08:10:53.000000000 +0100
549 /* Nonzero means emit debugging information only for symbols which are used. */
550 extern int flag_debug_only_used_symbols;
552 +/* Enumerate visibility settings. */
553 +#ifndef SYMBOL_VISIBILITY_DEFINED
554 +#define SYMBOL_VISIBILITY_DEFINED
555 +enum symbol_visibility
557 + VISIBILITY_DEFAULT,
558 + VISIBILITY_INTERNAL,
560 + VISIBILITY_PROTECTED
564 +/* The default visibility for all symbols (unless overridden). */
565 +extern enum symbol_visibility default_visibility;
567 +struct visibility_flags
569 + unsigned inpragma : 1; /* True when in #pragma GCC visibility. */
570 + unsigned inlineshidden : 1; /* True when -finlineshidden in effect. */
573 +/* Global visibility options. */
574 +extern struct visibility_flags visibility_options;
576 /* Nonzero means do optimizations. -opt. */
580 diff -aur gcc-3.4.0orig/gcc/opts.c gcc-3.4.0/gcc/opts.c
581 --- gcc-3.4.0orig/gcc/opts.c 2004-02-18 00:09:04.000000000 +0000
582 +++ gcc-3.4.0/gcc/opts.c 2004-05-09 08:10:53.000000000 +0100
584 write_symbols is set to DBX_DEBUG, XCOFF_DEBUG, or DWARF_DEBUG. */
585 bool use_gnu_debug_info_extensions;
587 +/* The default visibility for all symbols (unless overridden) */
588 +enum symbol_visibility default_visibility = VISIBILITY_DEFAULT;
590 +/* Global visibility options. */
591 +struct visibility_flags visibility_options;
593 /* Columns of --help display. */
594 static unsigned int columns = 80;
596 @@ -1440,6 +1446,21 @@
597 flag_verbose_asm = value;
600 + case OPT_fvisibility_:
602 + if(!strcmp(arg, "default"))
603 + default_visibility=VISIBILITY_DEFAULT;
604 + else if(!strcmp(arg, "internal"))
605 + default_visibility=VISIBILITY_INTERNAL;
606 + else if(!strcmp(arg, "hidden"))
607 + default_visibility=VISIBILITY_HIDDEN;
608 + else if(!strcmp(arg, "protected"))
609 + default_visibility=VISIBILITY_PROTECTED;
611 + error("unrecognised visibility value \"%s\"", arg);
619 diff -aur gcc-3.4.0orig/gcc/tree.c gcc-3.4.0/gcc/tree.c
620 --- gcc-3.4.0orig/gcc/tree.c 2004-02-05 22:01:35.000000000 +0000
621 +++ gcc-3.4.0/gcc/tree.c 2004-05-10 15:22:52.000000000 +0100
622 @@ -2563,6 +2563,11 @@
624 else if (code == FUNCTION_DECL)
625 DECL_MODE (t) = FUNCTION_MODE;
627 + /* Set default visibility to whatever the user supplied with
628 + visibility_specified depending on #pragma GCC visibility. */
629 + DECL_VISIBILITY (t) = default_visibility;
630 + DECL_VISIBILITYSPECIFIED (t) = visibility_options.inpragma;
635 diff -aur gcc-3.4.0orig/gcc/tree.h gcc-3.4.0/gcc/tree.h
636 --- gcc-3.4.0orig/gcc/tree.h 2004-02-08 01:52:43.000000000 +0000
637 +++ gcc-3.4.0/gcc/tree.h 2004-05-09 08:10:54.000000000 +0100
638 @@ -1499,6 +1499,10 @@
639 /* Value of the decls's visibility attribute */
640 #define DECL_VISIBILITY(NODE) (DECL_CHECK (NODE)->decl.visibility)
642 +/* Nonzero means that the decl had its visibility specified rather than
644 +#define DECL_VISIBILITYSPECIFIED(NODE) (DECL_CHECK (NODE)->decl.visibility_specified)
646 /* In a FUNCTION_DECL, nonzero if the function cannot be inlined. */
647 #define DECL_UNINLINABLE(NODE) (FUNCTION_DECL_CHECK (NODE)->decl.uninlinable)
649 @@ -1633,7 +1637,8 @@
650 || TREE_CODE (DECL_CONTEXT (EXP)) == TRANSLATION_UNIT_DECL)
652 /* Enumerate visibility settings. */
654 +#ifndef SYMBOL_VISIBILITY_DEFINED
655 +#define SYMBOL_VISIBILITY_DEFINED
656 enum symbol_visibility
659 @@ -1641,6 +1646,7 @@
667 @@ -1684,8 +1690,7 @@
668 unsigned thread_local_flag : 1;
669 unsigned declared_inline_flag : 1;
670 ENUM_BITFIELD(symbol_visibility) visibility : 2;
671 - unsigned unused : 1;
672 - /* one unused bit. */
673 + unsigned visibility_specified : 1;
675 unsigned lang_flag_0 : 1;
676 unsigned lang_flag_1 : 1;
678 diff -aur gcc-3.4.0orig/gcc/varasm.c gcc-3.4.0/gcc/varasm.c
679 --- gcc-3.4.0orig/gcc/varasm.c 2004-04-14 22:14:08.000000000 +0100
680 +++ gcc-3.4.0/gcc/varasm.c 2004-05-09 08:10:54.000000000 +0100
681 @@ -5150,8 +5150,8 @@
682 /* Static variables are always local. */
683 else if (! TREE_PUBLIC (exp))
685 - /* A variable is local if the user tells us so. */
686 - else if (DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
687 + /* A variable is local if the user explicitly tells us so. */
688 + else if (DECL_VISIBILITYSPECIFIED (exp) && DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
690 /* Otherwise, variables defined outside this object may not be local. */
691 else if (DECL_EXTERNAL (exp))
692 @@ -5159,6 +5159,9 @@
693 /* Linkonce and weak data are never local. */
694 else if (DECL_ONE_ONLY (exp) || DECL_WEAK (exp))
696 + /* If none of the above and visibility is not default, make local. */
697 + else if (DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
699 /* If PIC, then assume that any global name can be overridden by
700 symbols resolved from other modules. */