summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Gingold <gingold@adacore.com>2011-08-08 07:39:42 +0000
committerTristan Gingold <gingold@adacore.com>2011-08-08 07:39:42 +0000
commitd2521668e33529dff6dbcc356c36cd6a7fb6d36e (patch)
tree14c3a1a09e41f640315886ba043f4cc135600550
parent16283aab8a47f20c8a0c5fa7cb86ca0d72df6c32 (diff)
downloadgdb-d2521668e33529dff6dbcc356c36cd6a7fb6d36e.tar.gz
2011-08-08 Tristan Gingold <gingold@adacore.com>
* mach-o.c (bfd_mach_o_normalize_section_name): New function. (bfd_mach_o_convert_section_name_to_bfd): Use it. (bfd_mach_o_get_section_type_from_name): New function. (bfd_mach_o_get_section_attribute_from_name): Ditto. * mach-o.h (bfd_mach_o_section): Move bfdsection field at the end. Add comments. Add prototypes for the above new functions.
-rw-r--r--bfd/ChangeLog9
-rw-r--r--bfd/mach-o.c69
-rw-r--r--bfd/mach-o.h10
3 files changed, 70 insertions, 18 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 673f96ac77a..db8e2939ea6 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,12 @@
+2011-08-08 Tristan Gingold <gingold@adacore.com>
+
+ * mach-o.c (bfd_mach_o_normalize_section_name): New function.
+ (bfd_mach_o_convert_section_name_to_bfd): Use it.
+ (bfd_mach_o_get_section_type_from_name): New function.
+ (bfd_mach_o_get_section_attribute_from_name): Ditto.
+ * mach-o.h (bfd_mach_o_section): Move bfdsection field at the end.
+ Add comments. Add prototypes for the above new functions.
+
2011-08-05 Mark Kettenis <kettenis@gnu.org>
* netbsd-core.c (netbsd_core_vec): Init match_priority field.
diff --git a/bfd/mach-o.c b/bfd/mach-o.c
index 069414a665f..622cef54e61 100644
--- a/bfd/mach-o.c
+++ b/bfd/mach-o.c
@@ -144,44 +144,52 @@ static const struct mach_o_segment_name_xlat segsec_names_xlat[] =
{ NULL, NULL }
};
-
/* Mach-O to bfd names. */
-static void
-bfd_mach_o_convert_section_name_to_bfd (bfd *abfd, bfd_mach_o_section *section,
- char **name, flagword *flags)
+void
+bfd_mach_o_normalize_section_name (const char *segname, const char *sectname,
+ const char **name, flagword *flags)
{
const struct mach_o_segment_name_xlat *seg;
- char *res;
- unsigned int len;
- const char *pfx = "";
*name = NULL;
*flags = SEC_NO_FLAGS;
for (seg = segsec_names_xlat; seg->segname; seg++)
{
- if (strcmp (seg->segname, section->segname) == 0)
+ if (strcmp (seg->segname, segname) == 0)
{
const struct mach_o_section_name_xlat *sec;
for (sec = seg->sections; sec->mach_o_name; sec++)
{
- if (strcmp (sec->mach_o_name, section->sectname) == 0)
+ if (strcmp (sec->mach_o_name, sectname) == 0)
{
- len = strlen (sec->bfd_name);
- res = bfd_alloc (abfd, len + 1);
-
- if (res == NULL)
- return;
- strcpy (res, sec->bfd_name);
- *name = res;
+ *name = sec->bfd_name;
*flags = sec->flags;
return;
}
}
+ return;
}
}
+}
+
+static void
+bfd_mach_o_convert_section_name_to_bfd (bfd *abfd, bfd_mach_o_section *section,
+ const char **name, flagword *flags)
+{
+ char *res;
+ unsigned int len;
+ const char *pfx = "";
+
+ /* First search for a canonical name. */
+ bfd_mach_o_normalize_section_name (section->segname, section->sectname,
+ name, flags);
+
+ /* Return now if found. */
+ if (*name)
+ return;
len = strlen (section->segname) + 1
+ strlen (section->sectname) + 1;
@@ -201,6 +209,7 @@ bfd_mach_o_convert_section_name_to_bfd (bfd *abfd, bfd_mach_o_section *section,
return;
snprintf (res, len, "%s%s.%s", pfx, section->segname, section->sectname);
*name = res;
+ *flags = SEC_NO_FLAGS;
}
/* Convert a bfd section name to a Mach-O segment + section name. */
@@ -1496,7 +1505,7 @@ bfd_mach_o_make_bfd_section (bfd *abfd, bfd_mach_o_section *section,
unsigned long prot)
{
asection *bfdsec;
- char *sname;
+ const char *sname;
flagword flags;
bfd_mach_o_convert_section_name_to_bfd (abfd, section, &sname, &flags);
@@ -3404,6 +3413,32 @@ static bfd_mach_o_xlat_name bfd_mach_o_load_command_name[] =
{ NULL, 0}
};
+/* Get the section type from NAME. Return -1 if NAME is unknown. */
+
+unsigned int
+bfd_mach_o_get_section_type_from_name (const char *name)
+{
+ bfd_mach_o_xlat_name *x;
+
+ for (x = bfd_mach_o_section_type_name; x->name; x++)
+ if (strcmp (x->name, name) == 0)
+ return x->val;
+ return (unsigned int)-1;
+}
+
+/* Get the section attribute from NAME. Return -1 if NAME is unknown. */
+
+unsigned int
+bfd_mach_o_get_section_attribute_from_name (const char *name)
+{
+ bfd_mach_o_xlat_name *x;
+
+ for (x = bfd_mach_o_section_attribute_name; x->name; x++)
+ if (strcmp (x->name, name) == 0)
+ return x->val;
+ return (unsigned int)-1;
+}
+
static void
bfd_mach_o_print_private_header (bfd *abfd, FILE *file)
{
diff --git a/bfd/mach-o.h b/bfd/mach-o.h
index f0c2f6fe5ce..183076b44bd 100644
--- a/bfd/mach-o.h
+++ b/bfd/mach-o.h
@@ -46,7 +46,7 @@ bfd_mach_o_header;
typedef struct bfd_mach_o_section
{
- asection *bfdsection;
+ /* Fields present in the file. */
char sectname[16 + 1];
char segname[16 + 1];
bfd_vma addr;
@@ -59,6 +59,9 @@ typedef struct bfd_mach_o_section
unsigned long reserved1;
unsigned long reserved2;
unsigned long reserved3;
+
+ /* Corresponding bfd section. */
+ asection *bfdsection;
}
bfd_mach_o_section;
#define BFD_MACH_O_SECTION_SIZE 68
@@ -610,6 +613,11 @@ bfd_boolean bfd_mach_o_set_section_contents (bfd *, asection *, const void *,
file_ptr, bfd_size_type);
unsigned int bfd_mach_o_version (bfd *);
+unsigned int bfd_mach_o_get_section_type_from_name (const char *);
+unsigned int bfd_mach_o_get_section_attribute_from_name (const char *);
+void bfd_mach_o_normalize_section_name (const char *, const char *,
+ const char **, flagword *);
+
extern const bfd_target mach_o_fat_vec;
#endif /* _BFD_MACH_O_H_ */