This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Use ENCODE_SECTION_INFO and friends on Darwin
- To: gcc-patches at gcc dot gnu dot org
- Subject: Use ENCODE_SECTION_INFO and friends on Darwin
- From: Stan Shebs <shebs at apple dot com>
- Date: Thu, 07 Jun 2001 19:38:51 -0700
One of the dirty little secrets of the Mach-O PIC support in the
Darwin backend has been that it attempts to get a decl given only
an identifier. This is simply wrong, but was pretty thoroughly
wedged into the rest of the code. This patch fixes it by using
ENCODE_SECTION_INFO to add some chars onto the front of symbols,
representing various tidbits of info (data/function/defined) for
other skanky pieces of Mach-O support code that should also die,
but not today. Now at least GNAT for OS X should be unblocked...
Bootstrapped and testsuited on powerpc-apple-darwin1.3.3, committed
to mainline only.
Stan
2001-06-07 Stan Shebs <shebs@apple.com>
* config/darwin.h (ENCODE_SECTION_INFO): Define.
(REDO_SECTION_INFO_P): Ditto.
(STRIP_NAME_ENCODING): Ditto.
(ASM_DECLARE_OBJECT_NAME): Use ENCODE_SECTION_INFO.
(ASM_OUTPUT_ALIGNED_DECL_LOCAL): Ditto.
(ASM_OUTPUT_LABELREF): Use STRIP_NAME_ENCODING.
(GEN_LAZY_PTR_NAME_FOR_SYMBOL): Ditto.
* config/darwin.c: No longer include c-tree.h.
(machopic_classify_ident): Rewrite to use symbol encoding.
(lookup_name_darwin): Remove.
(machopic_non_lazy_ptr_name): Handle encoded symbols.
(machopic_stub_name): Use STRIP_NAME_ENCODING.
(machopic_validate_stub_or_non_lazy_ptr): Ditto.
(machopic_finish): Ditto, remove test of decl.
(update_non_lazy_ptrs): New function.
(darwin_encode_section_info): New function.
* config/darwin-protos.h: Declare it.
* config/rs6000/rs6000.c (machopic_output_stub): Use
STRIP_NAME_ENCODING.
Index: config/darwin-protos.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/darwin-protos.h,v
retrieving revision 1.1
diff -c -3 -p -r1.1 darwin-protos.h
*** darwin-protos.h 2001/04/12 02:12:59 1.1
--- darwin-protos.h 2001/06/08 02:09:49
*************** extern void machopic_define_ident PARAMS
*** 51,56 ****
--- 51,57 ----
extern void machopic_define_name PARAMS ((const char*));
extern int machopic_name_defined_p PARAMS ((const char*));
extern int machopic_ident_defined_p PARAMS ((tree));
+ extern void darwin_encode_section_info PARAMS ((tree));
#endif /* TREE_CODE */
Index: config/darwin.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/darwin.c,v
retrieving revision 1.1
diff -c -3 -p -r1.1 darwin.c
*** darwin.c 2001/04/12 02:12:59 1.1
--- darwin.c 2001/06/08 02:09:49
*************** Boston, MA 02111-1307, USA. */
*** 35,42 ****
#include "tree.h"
#include "expr.h"
#include "reload.h"
- /* need for IDENTIFIER_GLOBAL_VALUE and IDENTIFIER_LOCAL_VALUE */
- #include "c-tree.h"
#include "function.h"
#include "ggc.h"
--- 35,40 ----
*************** extern void machopic_output_stub PARAMS
*** 46,51 ****
--- 44,50 ----
static int machopic_data_defined_p PARAMS ((const char *));
static int func_name_maybe_scoped PARAMS ((const char *));
+ static void update_non_lazy_ptrs PARAMS ((const char *));
/* Make everything that used to go in the text section really go there. */
*************** machopic_classify_ident (ident)
*** 85,94 ****
&& name[3] == 'J'
&& name[4] == 'C'
&& name[5] == '_'));
! tree temp, decl = lookup_name_darwin (ident);
! if (!decl)
{
if (lprefix)
{
const char *name = IDENTIFIER_POINTER (ident);
--- 84,94 ----
&& name[3] == 'J'
&& name[4] == 'C'
&& name[5] == '_'));
! tree temp;
! if (name[0] != '!')
{
+ /* Here if no special encoding to be found. */
if (lprefix)
{
const char *name = IDENTIFIER_POINTER (ident);
*************** machopic_classify_ident (ident)
*** 114,149 ****
return MACHOPIC_UNDEFINED;
}
! /* variable declarations */
! else if (TREE_CODE (decl) == VAR_DECL)
! {
! if ((DECL_INITIAL (decl)
! || TREE_STATIC (decl))
! && ! TREE_PUBLIC (decl))
! return MACHOPIC_DEFINED_DATA;
! }
! /* function declarations */
! else if (TREE_CODE (decl) == FUNCTION_DECL
! && (!DECL_EXTERNAL (decl)))
! {
! if (TREE_STATIC (decl)
! || TREE_ASM_WRITTEN (decl))
! return MACHOPIC_DEFINED_FUNCTION;
! }
for (temp = machopic_defined_list; temp != NULL_TREE; temp = TREE_CHAIN (temp))
{
if (ident == TREE_VALUE (temp))
{
! if (TREE_CODE (decl) == FUNCTION_DECL)
return MACHOPIC_DEFINED_FUNCTION;
else
return MACHOPIC_DEFINED_DATA;
}
}
! if (TREE_CODE (decl) == FUNCTION_DECL)
{
if (lprefix)
return MACHOPIC_DEFINED_FUNCTION;
--- 114,137 ----
return MACHOPIC_UNDEFINED;
}
! else if (name[1] == 'D')
! return MACHOPIC_DEFINED_DATA;
! else if (name[1] == 'T')
! return MACHOPIC_DEFINED_FUNCTION;
for (temp = machopic_defined_list; temp != NULL_TREE; temp = TREE_CHAIN (temp))
{
if (ident == TREE_VALUE (temp))
{
! if (name[1] == 'T')
return MACHOPIC_DEFINED_FUNCTION;
else
return MACHOPIC_DEFINED_DATA;
}
}
! if (name[1] == 't' || name[1] == 'T')
{
if (lprefix)
return MACHOPIC_DEFINED_FUNCTION;
*************** machopic_define_name (name)
*** 218,237 ****
machopic_define_ident (get_identifier (name));
}
- tree
- lookup_name_darwin (name)
- tree name;
- {
- tree val;
-
- if (!global_bindings_p()
- && IDENTIFIER_LOCAL_VALUE (name))
- val = IDENTIFIER_LOCAL_VALUE (name);
- else
- val = IDENTIFIER_GLOBAL_VALUE (name);
- return val;
- }
-
/* This is a static to make inline functions work. The rtx
representing the PIC base symbol always points to here. */
--- 206,211 ----
*************** char *
*** 279,284 ****
--- 253,259 ----
machopic_non_lazy_ptr_name (name)
const char *name;
{
+ char *temp_name;
tree temp, ident = get_identifier (name);
for (temp = machopic_non_lazy_pointers;
*************** machopic_non_lazy_ptr_name (name)
*** 289,294 ****
--- 264,285 ----
return IDENTIFIER_POINTER (TREE_PURPOSE (temp));
}
+ STRIP_NAME_ENCODING (name, name);
+
+ /* Try again, but comparing names this time. */
+ for (temp = machopic_non_lazy_pointers;
+ temp != NULL_TREE;
+ temp = TREE_CHAIN (temp))
+ {
+ if (TREE_VALUE (temp))
+ {
+ temp_name = IDENTIFIER_POINTER (TREE_VALUE (temp));
+ STRIP_NAME_ENCODING (temp_name, temp_name);
+ if (strcmp (name, temp_name) == 0)
+ return IDENTIFIER_POINTER (TREE_PURPOSE (temp));
+ }
+ }
+
{
char *buffer;
tree ptr_name;
*************** machopic_stub_name (name)
*** 345,350 ****
--- 336,343 ----
return IDENTIFIER_POINTER (TREE_PURPOSE (temp));
}
+ STRIP_NAME_ENCODING (name, name);
+
{
char *buffer;
tree ptr_name;
*************** machopic_validate_stub_or_non_lazy_ptr (
*** 384,390 ****
const char *name;
int validate_stub;
{
! tree temp, ident = get_identifier (name);
for (temp = (validate_stub ? machopic_stubs : machopic_non_lazy_pointers);
temp != NULL_TREE;
--- 377,384 ----
const char *name;
int validate_stub;
{
! char *real_name;
! tree temp, ident = get_identifier (name), id2;
for (temp = (validate_stub ? machopic_stubs : machopic_non_lazy_pointers);
temp != NULL_TREE;
*************** machopic_validate_stub_or_non_lazy_ptr (
*** 396,401 ****
--- 390,399 ----
TREE_USED (temp) = 1;
if (TREE_CODE (TREE_VALUE (temp)) == IDENTIFIER_NODE)
TREE_SYMBOL_REFERENCED (TREE_VALUE (temp)) = 1;
+ STRIP_NAME_ENCODING (real_name, IDENTIFIER_POINTER (TREE_VALUE (temp)));
+ id2 = maybe_get_identifier (real_name);
+ if (id2)
+ TREE_SYMBOL_REFERENCED (id2) = 1;
}
}
*************** machopic_finish (asm_out_file)
*** 890,908 ****
char *stub_name = IDENTIFIER_POINTER (TREE_PURPOSE (temp));
char *sym;
char *stub;
- tree decl = lookup_name_darwin (TREE_VALUE (temp));
if (! TREE_USED (temp))
continue;
! /* Don't emit stubs for static inline functions which have not
! been compiled. */
! if (decl
! && TREE_CODE (decl) == FUNCTION_DECL
! && DECL_INLINE (decl)
! && ! TREE_PUBLIC (decl)
! && ! TREE_ASM_WRITTEN (decl))
! continue;
sym = alloca (strlen (sym_name) + 2);
if (sym_name[0] == '*' || sym_name[0] == '&')
--- 888,898 ----
char *stub_name = IDENTIFIER_POINTER (TREE_PURPOSE (temp));
char *sym;
char *stub;
if (! TREE_USED (temp))
continue;
! STRIP_NAME_ENCODING (sym_name, sym_name);
sym = alloca (strlen (sym_name) + 2);
if (sym_name[0] == '*' || sym_name[0] == '&')
*************** machopic_operand_p (op)
*** 999,1002 ****
--- 989,1072 ----
#endif
return 0;
+ }
+
+ /* This function records whether a given name corresponds to a defined
+ or undefined function or variable, for machopic_classify_ident to
+ use later. */
+
+ void
+ darwin_encode_section_info (decl)
+ tree decl;
+ {
+ char code = '\0';
+ int defined = 0;
+
+ if ((TREE_CODE (decl) == FUNCTION_DECL
+ || TREE_CODE (decl) == VAR_DECL)
+ && ((TREE_STATIC (decl)
+ && (!DECL_COMMON (decl) || !TREE_PUBLIC (decl)))
+ || DECL_INITIAL (decl)))
+ defined = 1;
+
+ if (TREE_CODE (decl) == FUNCTION_DECL)
+ code = (defined ? 'T' : 't');
+ else if (TREE_CODE (decl) == VAR_DECL)
+ code = (defined ? 'D' : 'd');
+
+ if (code != '\0')
+ {
+ rtx sym_ref = XEXP (DECL_RTL (decl), 0);
+
+ if (*(XSTR (sym_ref, 0)) == '!')
+ {
+ (XSTR(sym_ref, 0))[1] = code;
+ update_non_lazy_ptrs (XSTR (sym_ref, 0));
+ return;
+ }
+
+ {
+ size_t len = strlen (XSTR (sym_ref, 0));
+ size_t newlen = len + 4;
+ char *str = alloca (newlen);
+
+ str[0] = '!';
+ str[1] = code;
+ str[2] = '_';
+ str[3] = '_';
+ memcpy (str + 4, XSTR (sym_ref, 0), len + 1);
+
+ XSTR (sym_ref, 0) = ggc_alloc_string (str, newlen);
+ }
+ }
+ }
+
+ /* Scan the list of non-lazy pointers and update any recorded names whose
+ stripped name matches the argument. */
+
+ static void
+ update_non_lazy_ptrs (name)
+ const char *name;
+ {
+ char *name1, *name2;
+ tree temp;
+
+ STRIP_NAME_ENCODING (name1, name);
+
+ for (temp = machopic_non_lazy_pointers;
+ temp != NULL_TREE;
+ temp = TREE_CHAIN (temp))
+ {
+ char *sym_name = IDENTIFIER_POINTER (TREE_VALUE (temp));
+
+ if (*sym_name == '!')
+ {
+ STRIP_NAME_ENCODING (name2, sym_name);
+ if (strcmp (name1, name2) == 0)
+ {
+ IDENTIFIER_POINTER (TREE_VALUE (temp)) = name;
+ break;
+ }
+ }
+ }
}
Index: config/darwin.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/darwin.h,v
retrieving revision 1.4
diff -c -3 -p -r1.4 darwin.h
*** darwin.h 2001/05/15 02:17:14 1.4
--- darwin.h 2001/06/08 02:09:49
*************** do { text_section (); \
*** 234,239 ****
--- 234,243 ----
&& (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL))) \
|| DECL_INITIAL (DECL)) \
machopic_define_name (xname); \
+ if ((TREE_STATIC (DECL) \
+ && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL))) \
+ || DECL_INITIAL (DECL)) \
+ ENCODE_SECTION_INFO (DECL); \
ASM_OUTPUT_LABEL (FILE, xname); \
} while (0)
*************** do { text_section (); \
*** 243,248 ****
--- 247,253 ----
#undef ASM_OUTPUT_LABELREF
#define ASM_OUTPUT_LABELREF(FILE,NAME) \
do { \
+ STRIP_NAME_ENCODING (NAME, NAME); \
if (NAME[0] == '&') \
{ \
int len = strlen (NAME); \
*************** do { text_section (); \
*** 283,288 ****
--- 288,297 ----
if ((DECL) && ((TREE_STATIC (DECL) \
&& (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL))) \
|| DECL_INITIAL (DECL))) \
+ ENCODE_SECTION_INFO (DECL); \
+ if ((DECL) && ((TREE_STATIC (DECL) \
+ && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL))) \
+ || DECL_INITIAL (DECL))) \
machopic_define_name (NAME); \
} while (0)
*************** enum machopic_addr_class {
*** 705,710 ****
--- 714,729 ----
#define MACHOPIC_JUST_INDIRECT (flag_pic == 1)
#define MACHOPIC_PURE (flag_pic == 2)
+ #define ENCODE_SECTION_INFO(DECL) \
+ darwin_encode_section_info (DECL)
+
+ /* Be conservative and always redo the encoding. */
+
+ #define REDO_SECTION_INFO_P(DECL) (1)
+
+ #define STRIP_NAME_ENCODING(VAR,SYMBOL_NAME) \
+ ((VAR) = ((SYMBOL_NAME[0] == '!') ? (SYMBOL_NAME) + 4 : (SYMBOL_NAME)))
+
#define GEN_BINDER_NAME_FOR_STUB(BUF,STUB,STUB_LENGTH) \
do { \
const char *stub_ = (STUB); \
*************** enum machopic_addr_class {
*** 741,746 ****
--- 760,766 ----
do { \
const char *symbol_ = (SYMBOL); \
char *buffer_ = (BUF); \
+ STRIP_NAME_ENCODING (symbol_, symbol_); \
if (symbol_[0] == '"') \
{ \
strcpy (buffer_, "\"L"); \
Index: config/rs6000/rs6000.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/rs6000/rs6000.c,v
retrieving revision 1.182
diff -c -3 -p -r1.182 rs6000.c
*** rs6000.c 2001/05/21 18:38:22 1.182
--- rs6000.c 2001/06/08 02:09:51
*************** machopic_output_stub (file, symb, stub)
*** 8406,8411 ****
--- 8406,8414 ----
char *local_label_0, *local_label_1, *local_label_2;
static int label = 0;
+ /* Lose our funky encoding stuff so it doesn't contaminate the stub. */
+ STRIP_NAME_ENCODING (symb, symb);
+
label += 1;
length = strlen (stub);