1
/* Add integer to a section.
2
Copyright (C) 2002, 2005 Red Hat, Inc.
3
This file is part of Red Hat elfutils.
4
Written by Ulrich Drepper <drepper@redhat.com>, 2002.
6
Red Hat elfutils is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by the
8
Free Software Foundation; version 2 of the License.
10
Red Hat elfutils is distributed in the hope that it will be useful, but
11
WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
General Public License for more details.
15
You should have received a copy of the GNU General Public License along
16
with Red Hat elfutils; if not, write to the Free Software Foundation,
17
Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
19
Red Hat elfutils is an included package of the Open Invention Network.
20
An included package of the Open Invention Network is a package for which
21
Open Invention Network licensees cross-license their patents. No patent
22
license is granted, either expressly or impliedly, by designation as an
23
included package. Should you wish to participate in the Open Invention
24
Network licensing program, please visit www.openinventionnetwork.com
25
<http://www.openinventionnetwork.com>. */
42
#define FCT(size) _FCT(size)
43
#define _FCT(size) asm_addint##size
44
#define TYPE(size) _TYPE(size)
45
#define _TYPE(size) int##size##_t
46
#define BSWAP(size) _BSWAP(size)
47
#define _BSWAP(size) bswap_##size
51
FCT(SIZE) (asmscn, num)
58
if (asmscn->type == SHT_NOBITS && unlikely (num != 0))
60
__libasm_seterrno (ASM_E_TYPE);
64
if (unlikely (asmscn->ctx->textp))
66
// XXX Needs to use backend specified pseudo-ops
68
fprintf (asmscn->ctx->out.file, "\t.byte\t%" PRId8 "\n", (int8_t) num);
70
fprintf (asmscn->ctx->out.file, "\t.value\t%" PRId16 "\n",
73
fprintf (asmscn->ctx->out.file, "\t.long\t%" PRId32 "\n",
77
// XXX This is not necessary for 64-bit machines
78
bool is_leb = (elf_getident (asmscn->ctx->out.elf, NULL)[EI_DATA]
81
fprintf (asmscn->ctx->out.file,
82
"\t.long\t%" PRId32 "\n\t.long\t%" PRId32 "\n",
84
? num % 0x100000000ll : num / 0x100000000ll),
86
? num / 0x100000000ll : num % 0x100000000ll));
92
bool is_leb = (elf_getident (asmscn->ctx->out.elf, NULL)[EI_DATA]
97
/* Make sure we have enough room. */
98
if (__libasm_ensure_section_space (asmscn, SIZE / 8) != 0)
102
if ((BYTE_ORDER == LITTLE_ENDIAN && !is_leb)
103
|| (BYTE_ORDER == BIG_ENDIAN && is_leb))
104
var = BSWAP(SIZE) (var);
107
/* Copy the variable value. */
108
if (likely (asmscn->type == SHT_NOBITS))
109
memcpy (&asmscn->content->data[asmscn->content->len], &var, SIZE / 8);
111
/* Adjust the pointer in the data buffer. */
112
asmscn->content->len += SIZE / 8;
114
/* Increment the offset in the (sub)section. */
115
asmscn->offset += SIZE / 8;