1 /* Define new symbol for current position in given section.
2 Copyright (C) 2002, 2005 Red Hat, Inc.
3 This file is part of elfutils.
4 Written by Ulrich Drepper <drepper@redhat.com>, 2002.
6 This file is free software; you can redistribute it and/or modify
7 it under the terms of either
9 * the GNU Lesser General Public License as published by the Free
10 Software Foundation; either version 3 of the License, or (at
11 your option) any later version
15 * the GNU General Public License as published by the Free
16 Software Foundation; either version 2 of the License, or (at
17 your option) any later version
19 or both in parallel, as here.
21 elfutils is distributed in the hope that it will be useful, but
22 WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 General Public License for more details.
26 You should have received copies of the GNU General Public License and
27 the GNU Lesser General Public License along with this program. If
28 not, see <http://www.gnu.org/licenses/>. */
44 asm_newsym (asmscn, name, size, type, binding)
52 char tempsym[TEMPSYMLEN];
56 /* Something went wrong before. */
59 /* Generate a temporary symbol if necessary. */
62 /* If a local symbol name is created the symbol better have
64 if (binding != STB_LOCAL)
66 __libasm_seterrno (ASM_E_INVALID);
70 // XXX This requires getting the format from the machine backend. */
71 snprintf (tempsym, TEMPSYMLEN, ".L%07u", asmscn->ctx->tempsym_count++);
76 size_t name_len = strlen (name) + 1;
78 result = (AsmSym_t *) malloc (sizeof (AsmSym_t) + name_len);
82 rwlock_wrlock (asmscn->ctx->lock);
85 result->offset = asmscn->offset;
88 result->binding = binding;
90 result->strent = ebl_strtabadd (asmscn->ctx->symbol_strtab,
91 memcpy (result + 1, name, name_len), 0);
93 if (unlikely (asmscn->ctx->textp))
95 /* We are only interested in the name and don't need to know whether
96 it is a local name or not. */
97 /* First print the binding pseudo-op. */
98 if (binding == STB_GLOBAL)
99 fprintf (asmscn->ctx->out.file, "\t.globl\t%s\n", name);
100 else if (binding == STB_WEAK)
101 fprintf (asmscn->ctx->out.file, "\t.weak\t%s\n", name);
103 /* Next the symbol type. */
104 if (type == STT_OBJECT)
105 fprintf (asmscn->ctx->out.file, "\t.type\t%s,@object\n", name);
106 else if (type == STT_FUNC)
107 fprintf (asmscn->ctx->out.file, "\t.type\t%s,@function\n", name);
109 /* Finally the size and the label. */
110 fprintf (asmscn->ctx->out.file, "\t.size\t%s,%" PRIuMAX "\n%s:\n",
111 name, (uintmax_t) size, name);
115 /* Put the symbol in the hash table so that we can later find it. */
116 if (asm_symbol_tab_insert (&asmscn->ctx->symbol_tab, elf_hash (name),
119 /* The symbol already exists. */
120 __libasm_seterrno (ASM_E_DUPLSYM);
121 /* Note that we can free the entry since there must be no
122 reference in the string table to the string. We can only
123 fail to insert the symbol into the symbol table if there
124 is already a symbol with this name. In this case the
125 ebl_strtabadd function would use the previously provided
130 else if (name != tempsym && asm_emit_symbol_p (name))
131 /* Only count non-private symbols. */
132 ++asmscn->ctx->nsymbol_tab;
135 rwlock_unlock (asmscn->ctx->lock);