#endif
}
-/* Deduplicate size expressions. We might get into trouble with
- multiple freeing or use after free if we leave them pointing to the
- same expressionS. */
-
+/* If size is unset, copy size from src. Because we don't track whether
+ .size has been used, we can't differentiate .size dest, 0 from the case
+ where dest's size is unset. */
void
-elf_obj_symbol_clone_hook (symbolS *newsym, symbolS *orgsym ATTRIBUTE_UNUSED)
+elf_copy_symbol_size (symbolS *dest, symbolS *src)
{
- struct elf_obj_sy *newelf = symbol_get_obj (newsym);
- if (newelf->size)
+ struct elf_obj_sy *srcelf = symbol_get_obj (src);
+ struct elf_obj_sy *destelf = symbol_get_obj (dest);
+ if (!destelf->size && S_GET_SIZE (dest) == 0)
{
- expressionS *exp = XNEW (expressionS);
- *exp = *newelf->size;
- newelf->size = exp;
+ destelf->size = srcelf->size;
+ S_SET_SIZE (dest, S_GET_SIZE (src));
}
}
void
elf_copy_symbol_attributes (symbolS *dest, symbolS *src)
{
- struct elf_obj_sy *srcelf = symbol_get_obj (src);
- struct elf_obj_sy *destelf = symbol_get_obj (dest);
- /* If size is unset, copy size from src. Because we don't track whether
- .size has been used, we can't differentiate .size dest, 0 from the case
- where dest's size is unset. */
- if (!destelf->size && S_GET_SIZE (dest) == 0)
- {
- if (srcelf->size)
- {
- destelf->size = XNEW (expressionS);
- *destelf->size = *srcelf->size;
- }
- S_SET_SIZE (dest, S_GET_SIZE (src));
- }
+ elf_copy_symbol_size (dest, src);
/* Don't copy visibility. */
S_SET_OTHER (dest, (ELF_ST_VISIBILITY (S_GET_OTHER (dest))
| (S_GET_OTHER (src) & ~ELF_ST_VISIBILITY (-1))));
if (exp.X_op == O_constant)
{
S_SET_SIZE (sym, exp.X_add_number);
- xfree (symbol_get_obj (sym)->size);
symbol_get_obj (sym)->size = NULL;
}
else
{
- symbol_get_obj (sym)->size = XNEW (expressionS);
+ symbol_get_obj (sym)->size = notes_alloc (sizeof (exp));
*symbol_get_obj (sym)->size = exp;
}
as_warn (_(".size expression for %s "
"does not evaluate to a constant"), S_GET_NAME (symp));
}
- free (sy_obj->size);
sy_obj->size = NULL;
}
#endif
elf_obj_read_begin_hook,
elf_obj_symbol_new_hook,
- elf_obj_symbol_clone_hook,
+ 0,
elf_adjust_symtab
};
#define obj_symbol_new_hook elf_obj_symbol_new_hook
#endif
-void elf_obj_symbol_clone_hook (symbolS *, symbolS *);
-#ifndef obj_symbol_clone_hook
-#define obj_symbol_clone_hook elf_obj_symbol_clone_hook
-#endif
-
+void elf_copy_symbol_size (symbolS *, symbolS *);
void elf_copy_symbol_attributes (symbolS *, symbolS *);
#ifndef OBJ_COPY_SYMBOL_ATTRIBUTES
#define OBJ_COPY_SYMBOL_ATTRIBUTES(DEST, SRC) \
{
AARCH64_GET_FLAG (dest) = AARCH64_GET_FLAG (src);
}
-
-#ifdef OBJ_ELF
-/* Same as elf_copy_symbol_attributes, but without copying st_other.
- This is needed so AArch64 specific st_other values can be independently
- specified for an IFUNC resolver (that is called by the dynamic linker)
- and the symbol it resolves (aliased to the resolver). In particular,
- if a function symbol has special st_other value set via directives,
- then attaching an IFUNC resolver to that symbol should not override
- the st_other setting. Requiring the directive on the IFUNC resolver
- symbol would be unexpected and problematic in C code, where the two
- symbols appear as two independent function declarations. */
-
-void
-aarch64_elf_copy_symbol_attributes (symbolS *dest, symbolS *src)
-{
- struct elf_obj_sy *srcelf = symbol_get_obj (src);
- struct elf_obj_sy *destelf = symbol_get_obj (dest);
- /* If size is unset, copy size from src. Because we don't track whether
- .size has been used, we can't differentiate .size dest, 0 from the case
- where dest's size is unset. */
- if (!destelf->size && S_GET_SIZE (dest) == 0)
- {
- if (srcelf->size)
- {
- destelf->size = XNEW (expressionS);
- *destelf->size = *srcelf->size;
- }
- S_SET_SIZE (dest, S_GET_SIZE (src));
- }
-}
-#endif
#endif
#ifdef OBJ_ELF
-void aarch64_elf_copy_symbol_attributes (symbolS *, symbolS *);
+/* Don't copy st_other.
+ This is needed so AArch64 specific st_other values can be independently
+ specified for an IFUNC resolver (that is called by the dynamic linker)
+ and the symbol it resolves (aliased to the resolver). In particular,
+ if a function symbol has special st_other value set via directives,
+ then attaching an IFUNC resolver to that symbol should not override
+ the st_other setting. Requiring the directive on the IFUNC resolver
+ symbol would be unexpected and problematic in C code, where the two
+ symbols appear as two independent function declarations. */
#define OBJ_COPY_SYMBOL_ATTRIBUTES(DEST, SRC) \
- aarch64_elf_copy_symbol_attributes (DEST, SRC)
+ elf_copy_symbol_size (DEST, SRC)
#endif
#define TC_START_LABEL(STR, NUL_CHAR, NEXT_CHAR) \
if (sym && cur_frame_data)
{
OBJ_SYMFIELD_TYPE *obj = symbol_get_obj (sym);
- expressionS *exp = XNEW (expressionS);
+ expressionS *exp = notes_alloc (sizeof (*exp));
obj->size = exp;
exp->X_op = O_subtract;
S_SET_SIZE (sym, frag_now_fix () - S_GET_VALUE (sym));
else
{
- symbol_get_obj (sym)->size = XNEW (expressionS);
- symbol_get_obj (sym)->size->X_op = O_subtract;
- symbol_get_obj (sym)->size->X_add_symbol
+ OBJ_SYMFIELD_TYPE *obj = symbol_get_obj (sym);
+ obj->size = notes_alloc (sizeof (*obj->size));
+ obj->size->X_op = O_subtract;
+ obj->size->X_add_symbol
= symbol_new (FAKE_LABEL_NAME, now_seg,
frag_now, frag_now_fix ());
- symbol_get_obj (sym)->size->X_op_symbol = sym;
- symbol_get_obj (sym)->size->X_add_number = 0;
+ obj->size->X_op_symbol = sym;
+ obj->size->X_add_number = 0;
}
}
}
if (exp.X_op == O_constant)
{
S_SET_SIZE (last_proc_sym, exp.X_add_number);
- if (symbol_get_obj (last_proc_sym)->size)
- {
- xfree (symbol_get_obj (last_proc_sym)->size);
- symbol_get_obj (last_proc_sym)->size = NULL;
- }
+ symbol_get_obj (last_proc_sym)->size = NULL;
}
else
{
- symbol_get_obj (last_proc_sym)->size =
- (expressionS *) xmalloc (sizeof (expressionS));
+ symbol_get_obj (last_proc_sym)->size = notes_alloc (sizeof (exp));
*symbol_get_obj (last_proc_sym)->size = exp;
}
if (p && cur_proc_ptr)
{
OBJ_SYMFIELD_TYPE *obj = symbol_get_obj (p);
- expressionS *exp = XNEW (expressionS);
+ expressionS *exp = notes_alloc (sizeof (*exp));
obj->size = exp;
exp->X_op = O_subtract;
elfsym->internal_elf_sym.st_other |= STO_RISCV_VARIANT_CC;
}
-/* Same as elf_copy_symbol_attributes, but without copying st_other.
- This is needed so RISC-V specific st_other values can be independently
- specified for an IFUNC resolver (that is called by the dynamic linker)
- and the symbol it resolves (aliased to the resolver). In particular,
- if a function symbol has special st_other value set via directives,
- then attaching an IFUNC resolver to that symbol should not override
- the st_other setting. Requiring the directive on the IFUNC resolver
- symbol would be unexpected and problematic in C code, where the two
- symbols appear as two independent function declarations. */
-
-void
-riscv_elf_copy_symbol_attributes (symbolS *dest, symbolS *src)
-{
- struct elf_obj_sy *srcelf = symbol_get_obj (src);
- struct elf_obj_sy *destelf = symbol_get_obj (dest);
- /* If size is unset, copy size from src. Because we don't track whether
- .size has been used, we can't differentiate .size dest, 0 from the case
- where dest's size is unset. */
- if (!destelf->size && S_GET_SIZE (dest) == 0)
- {
- if (srcelf->size)
- {
- destelf->size = XNEW (expressionS);
- *destelf->size = *srcelf->size;
- }
- S_SET_SIZE (dest, S_GET_SIZE (src));
- }
-}
-
/* RISC-V pseudo-ops table. */
static const pseudo_typeS riscv_pseudo_table[] =
{
#define obj_adjust_symtab() riscv_adjust_symtab ()
extern void riscv_adjust_symtab (void);
-void riscv_elf_copy_symbol_attributes (symbolS *, symbolS *);
+/* Don't copy st_other.
+ This is needed so RISC-V specific st_other values can be independently
+ specified for an IFUNC resolver (that is called by the dynamic linker)
+ and the symbol it resolves (aliased to the resolver). In particular,
+ if a function symbol has special st_other value set via directives,
+ then attaching an IFUNC resolver to that symbol should not override
+ the st_other setting. Requiring the directive on the IFUNC resolver
+ symbol would be unexpected and problematic in C code, where the two
+ symbols appear as two independent function declarations. */
#define OBJ_COPY_SYMBOL_ATTRIBUTES(DEST, SRC) \
- riscv_elf_copy_symbol_attributes (DEST, SRC)
+ elf_copy_symbol_size (DEST, SRC)
#endif /* TC_RISCV */