1 /* ELF object file format
2 Copyright (C) 1992, 1993 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2,
9 or (at your option) any later version.
11 GAS is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
14 the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public
17 License along with GAS; see the file COPYING. If not, write
18 to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* HP PA-RISC support was contributed by the Center for Software Science
21 at the University of Utah. */
24 #include "aout/stab_gnu.h"
27 static void obj_elf_stab
PARAMS ((int what
));
28 static void obj_elf_line
PARAMS ((void));
29 static void obj_elf_desc
PARAMS ((void));
30 static void obj_elf_version
PARAMS ((void));
31 static void obj_elf_section
PARAMS ((int));
32 static void obj_elf_size
PARAMS ((void));
33 static void obj_elf_type
PARAMS ((void));
34 static void obj_elf_ident
PARAMS ((void));
36 const pseudo_typeS obj_pseudo_table
[] = {
37 { "ident", obj_elf_ident
, 0 },
38 { "section", obj_elf_section
, 0 },
39 { "size", obj_elf_size
, 0 },
40 { "type", obj_elf_type
, 0 },
41 { "version", obj_elf_version
, 0 },
43 /* These are used for stabs-in-elf configurations. */
44 { "desc", obj_elf_desc
, 0 },
45 { "line", obj_elf_line
, 0 },
46 { "stabd", obj_elf_stab
, 'd' },
47 { "stabn", obj_elf_stab
, 'n' },
48 { "stabs", obj_elf_stab
, 's' },
49 /* This is used on Solaris 2.x on SPARC, but not supported yet. */
50 { "xstabs", s_ignore
, 0 },
52 { NULL
} /* end sentinel */
62 /* Initialize this with inclusive-or of all flags that can be cleared
63 by attributes, but not set by them. Also include flags that won't
64 get set properly in the assembler, but which the user/compiler
65 shouldn't be expected to set. */
66 flagword flags
= SEC_READONLY
| SEC_ALLOC
| SEC_RELOC
;
67 /* Initialize this with the default flags to be used if none are
69 flagword default_flags
= SEC_ALLOC
| SEC_RELOC
;
71 string
= demand_copy_C_string (&xxx
);
73 if (*input_line_pointer
!= ',')
74 flags
= default_flags
;
75 while (*input_line_pointer
== ',')
82 if (*input_line_pointer
!= '#')
84 as_bad ("unrecognized syntax in .section command");
85 ignore_rest_of_line ();
90 #define CHECK(X,BIT,NEG) \
91 if (!strncmp(X,input_line_pointer,len = sizeof(X) - 1)) { \
92 bit = BIT; inv = NEG; goto match; }
94 CHECK ("write", SEC_READONLY
, 1);
95 CHECK ("alloc", SEC_ALLOC
, 0);
98 p
= input_line_pointer
;
99 while (!is_end_of_line
[*p
] && *p
!= 0 && *p
!= ',')
103 as_bad ("unrecognized section attribute `%s' ignored",
113 input_line_pointer
+= len
;
115 demand_empty_rest_of_line ();
117 sec
= bfd_get_section_by_name (stdoutput
, string
);
120 sec
= bfd_make_section_old_way (stdoutput
, string
);
121 bfd_set_section_flags (stdoutput
, sec
,
122 /* @@ What should the flags be?? */
124 sec
->output_section
= sec
;
126 subseg_change (sec
, 0);
130 /* pa-spaces.c -- Space/subspace support for the HP PA-RISC version of GAS */
132 /* for space, subspace, and symbol maintenance on HP 9000 Series 800 */
134 space_dict_chainS
*space_dict_root
;
135 space_dict_chainS
*space_dict_last
;
137 space_dict_chainS
*current_space
;
138 subspace_dict_chainS
*current_subspace
;
141 symbolS
*start_symbol_root
;
142 symbolS
*start_symbol_last
;
144 #if 0 /* I really don't think this belongs in this file. */
145 void pa_spaces_begin()
147 space_dict_chainS
*space
;
149 subsegT now_subseg
= now_subseg
;
151 space_dict_root
= NULL
;
152 space_dict_last
= NULL
;
154 start_symbol_root
= NULL
;
155 start_symbol_last
= NULL
;
157 /* create default space and subspace dictionaries */
160 while ( pa_def_spaces
[i
].name
) {
161 if ( pa_def_spaces
[i
].alias
)
162 pa_def_spaces
[i
].segment
= subseg_new(pa_def_spaces
[i
].alias
,0);
164 pa_def_spaces
[i
].segment
= bfd_make_section_old_way(stdoutput
,pa_def_spaces
[i
].name
);
166 create_new_space(pa_def_spaces
[i
].name
,pa_def_spaces
[i
].spnum
,
167 pa_def_spaces
[i
].loadable
,pa_def_spaces
[i
].defined
,
168 pa_def_spaces
[i
].private,pa_def_spaces
[i
].sort
,0,
169 pa_def_spaces
[i
].segment
);
174 while ( pa_def_subspaces
[i
].name
) {
175 space
= pa_segment_to_space(pa_def_spaces
[pa_def_subspaces
[i
].def_space_index
].segment
);
177 create_new_subspace(space
,
178 pa_def_subspaces
[i
].name
,pa_def_subspaces
[i
].defined
,
179 pa_def_subspaces
[i
].loadable
,
180 pa_def_subspaces
[i
].code_only
,pa_def_subspaces
[i
].common
,
181 pa_def_subspaces
[i
].dup_common
,pa_def_subspaces
[i
].zero
,
182 pa_def_subspaces
[i
].sort
,pa_def_subspaces
[i
].access
,
183 pa_def_subspaces
[i
].space_index
,
184 pa_def_subspaces
[i
].alignment
,
185 pa_def_subspaces
[i
].quadrant
,
186 pa_def_spaces
[pa_def_subspaces
[i
].def_space_index
].segment
);
187 subseg_new(pa_def_subspaces
[i
].name
,pa_def_subspaces
[i
].subsegment
);
190 as_fatal("Internal error: space missing for subspace \"%s\"\n",
191 pa_def_subspaces
[i
].name
);
196 space_dict_chainS
*create_new_space(name
,spnum
,loadable
,defined
,private,sort
,defined_in_file
,seg
)
203 char defined_in_file
;
207 Elf_Internal_Shdr
*new_space
;
208 space_dict_chainS
*chain_entry
;
210 new_space
= (Elf_Internal_Shdr
*)xmalloc(sizeof(Elf_Internal_Shdr
));
212 as_fatal("Out of memory: could not allocate new Elf_Internal_Shdr: %s\n",name
);
215 new_space->space_number = spnum;
216 new_space->is_loadable = loadable & 1;
217 new_space->is_defined = defined & 1;
218 new_space->is_private = private & 1;
219 new_space->sort_key = sort & 0xff;
221 new_space->loader_fix_index = ~0;
222 new_space->loader_fix_quantity = 0;
223 new_space->init_pointer_index = ~0;
224 new_space->init_pointer_quantity = 0;
225 new_space->subspace_quantity = 0;
228 chain_entry
= (space_dict_chainS
*)xmalloc(sizeof(space_dict_chainS
));
230 as_fatal("Out of memory: could not allocate new space chain entry: %s\n",name
);
232 SPACE_NAME(chain_entry
) = (char *)xmalloc(strlen(name
)+1);
233 strcpy(SPACE_NAME(chain_entry
),name
);
235 chain_entry
->sd_entry
= new_space
;
236 chain_entry
->sd_defined
= defined_in_file
;
237 chain_entry
->sd_seg
= seg
;
238 chain_entry
->sd_last_subseg
= -1;
239 chain_entry
->sd_next
= NULL
;
241 SPACE_SPNUM(chain_entry
) = spnum
;
242 SPACE_LOADABLE(chain_entry
) = loadable
& 1;
243 SPACE_DEFINED(chain_entry
) = defined
& 1;
244 SPACE_PRIVATE(chain_entry
) = private & 1;
245 SPACE_SORT(chain_entry
) = sort
& 0xff;
247 /* find spot for the new space based on its sort key */
249 if ( !space_dict_last
)
250 space_dict_last
= chain_entry
;
252 if ( space_dict_root
== NULL
) /* if root is null, it is very easy */
253 space_dict_root
= chain_entry
;
256 space_dict_chainS
*sdcP
;
257 space_dict_chainS
*last_sdcP
;
259 sdcP
= space_dict_root
;
263 if ( SPACE_SORT(sdcP
) < SPACE_SORT(chain_entry
) ) {
265 sdcP
= sdcP
->sd_next
;
267 else if ( SPACE_SORT(sdcP
) == SPACE_SORT(chain_entry
) ) {
269 sdcP
= sdcP
->sd_next
;
271 else if ( SPACE_SORT(sdcP
) > SPACE_SORT(chain_entry
) ) {
277 chain_entry
->sd_next
= sdcP
;
278 last_sdcP
->sd_next
= chain_entry
;
281 space_dict_root
= chain_entry
;
282 chain_entry
->sd_next
= sdcP
;
285 if ( chain_entry
->sd_next
== NULL
)
286 space_dict_last
= chain_entry
;
293 *create_new_subspace(space
,name
,defined
,loadable
,code_only
,common
,dup_common
,
294 is_zero
,sort
,access
,space_index
,alignment
,quadrant
,seg
)
295 space_dict_chainS
*space
;
297 char defined
,loadable
,code_only
,common
,dup_common
,is_zero
;
305 Elf_Internal_Shdr
* new_subspace
;
306 subspace_dict_chainS
* chain_entry
;
307 symbolS
* start_symbol
;
309 new_subspace
= (Elf_Internal_Shdr
*)xmalloc(sizeof(Elf_Internal_Shdr
));
311 as_fatal("Out of memory: could not allocate new Elf_Internal_Shdr: %s\n",
315 new_subspace->space_index = space_index;
316 new_subspace->fixup_request_index = ~0;
319 chain_entry
= (subspace_dict_chainS
*)xmalloc(sizeof(subspace_dict_chainS
));
321 as_fatal("Out of memory: could not allocate new subspace chain entry: %s\n",name
);
323 chain_entry
->ssd_entry
= new_subspace
;
324 SUBSPACE_NAME(chain_entry
) = (char *)xmalloc(strlen(name
)+1);
325 strcpy(SUBSPACE_NAME(chain_entry
),name
);
327 SUBSPACE_ACCESS(chain_entry
) = access
& 0x7f;
328 SUBSPACE_LOADABLE(chain_entry
) = loadable
& 1;
329 SUBSPACE_COMMON(chain_entry
) = common
& 1;
330 SUBSPACE_DUP_COMM(chain_entry
) = dup_common
& 1;
331 SUBSPACE_SORT(chain_entry
) = sort
& 0xff;
332 SET_SUBSPACE_CODE_ONLY(chain_entry
,code_only
& 1);
333 SUBSPACE_ALIGN(chain_entry
) = alignment
& 0xffff;
334 SUBSPACE_QUADRANT(chain_entry
) = quadrant
& 0x3;
335 SUBSPACE_SUBSPACE_START(chain_entry
) = pa_subspace_start(space
,quadrant
);
337 chain_entry
->ssd_defined
= defined
;
338 chain_entry
->ssd_space_number
= space_index
;
339 chain_entry
->ssd_subseg
= pa_next_subseg(space
);
340 chain_entry
->ssd_seg
= seg
;
341 SUBSPACE_ZERO(chain_entry
) = is_zero
;
342 chain_entry
->ssd_last_align
= 1;
343 chain_entry
->ssd_next
= NULL
;
345 /* find spot for the new subspace based on its sort key */
347 if ( space
->sd_subspaces
== NULL
) /* if root is null, it is very easy */
348 space
->sd_subspaces
= chain_entry
;
351 subspace_dict_chainS
*ssdcP
;
352 subspace_dict_chainS
*last_ssdcP
;
354 ssdcP
= space
->sd_subspaces
;
358 if ( SUBSPACE_SORT(ssdcP
) < SUBSPACE_SORT(chain_entry
) ) {
360 ssdcP
= ssdcP
->ssd_next
;
362 else if ( SUBSPACE_SORT(ssdcP
) == SUBSPACE_SORT(chain_entry
) ) {
364 ssdcP
= ssdcP
->ssd_next
;
366 else if ( SUBSPACE_SORT(ssdcP
) > SUBSPACE_SORT(chain_entry
) ) {
372 chain_entry
->ssd_next
= ssdcP
;
373 last_ssdcP
->ssd_next
= chain_entry
;
376 space
->sd_subspaces
= chain_entry
;
377 chain_entry
->ssd_next
= ssdcP
;
381 start_symbol
= pa_set_start_symbol(seg
,space
->sd_last_subseg
);
382 chain_entry
->ssd_start_sym
= start_symbol
;
388 *update_subspace(name
,defined
,loadable
,code_only
,common
,dup_common
,sort
,zero
,
389 access
,space_index
,alignment
,quadrant
,subseg
)
391 char defined
,loadable
,code_only
,common
,dup_common
,zero
;
399 subspace_dict_chainS
*chain_entry
;
400 subspace_dict_chainS
*is_defined_subspace();
402 if ( (chain_entry
= is_defined_subspace(name
,subseg
)) ) {
404 SUBSPACE_ACCESS(chain_entry
) = access
& 0x7f;
405 SUBSPACE_LOADABLE(chain_entry
) = loadable
& 1;
406 SUBSPACE_COMMON(chain_entry
) = common
& 1;
407 SUBSPACE_DUP_COMM(chain_entry
) = dup_common
& 1;
408 SET_SUBSPACE_CODE_ONLY(chain_entry
,code_only
& 1);
409 SUBSPACE_SORT(chain_entry
) = sort
& 0xff;
410 /* chain_entry->ssd_entry->space_index = space_index; */
411 SUBSPACE_ALIGN(chain_entry
) = alignment
& 0xffff;
412 SUBSPACE_QUADRANT(chain_entry
) = quadrant
& 0x3;
414 chain_entry
->ssd_defined
= defined
;
415 chain_entry
->ssd_space_number
= space_index
;
416 SUBSPACE_ZERO(chain_entry
) = zero
;
425 space_dict_chainS
*is_defined_space(name
)
428 space_dict_chainS
*spaceCh
;
430 for (spaceCh
= space_dict_root
;spaceCh
;spaceCh
=spaceCh
->sd_next
) {
431 if ( strcmp(SPACE_NAME(spaceCh
),name
) == 0 ) {
439 space_dict_chainS
*pa_segment_to_space(seg
)
442 space_dict_chainS
*spaceCh
;
444 for (spaceCh
= space_dict_root
;spaceCh
;spaceCh
=spaceCh
->sd_next
) {
445 if ( spaceCh
->sd_seg
== seg
) {
453 subspace_dict_chainS
*is_defined_subspace(name
,subseg
)
457 space_dict_chainS
*spaceCh
;
458 subspace_dict_chainS
*subspCh
;
460 for ( spaceCh
= space_dict_root
; spaceCh
; spaceCh
= spaceCh
->sd_next
) {
461 for ( subspCh
= spaceCh
->sd_subspaces
; subspCh
; subspCh
=subspCh
->ssd_next
) {
463 if ( strcmp(SUBSPACE_NAME(subspCh),name) == 0 &&
464 subspCh->ssd_subseg == subseg ) {
466 if ( strcmp(SUBSPACE_NAME(subspCh
),name
) == 0 ) {
474 subspace_dict_chainS
*pa_subsegment_to_subspace(seg
,subseg
)
478 space_dict_chainS
*spaceCh
;
479 subspace_dict_chainS
*subspCh
;
481 for ( spaceCh
= space_dict_root
; spaceCh
; spaceCh
= spaceCh
->sd_next
) {
482 if ( spaceCh
->sd_seg
== seg
) {
483 for (subspCh
= spaceCh
->sd_subspaces
;subspCh
;subspCh
=subspCh
->ssd_next
) {
484 if ( subspCh
->ssd_subseg
== (int)subseg
) {
494 space_dict_chainS
*pa_find_space_by_number(number
)
497 space_dict_chainS
*spaceCh
;
499 for (spaceCh
= space_dict_root
;spaceCh
;spaceCh
=spaceCh
->sd_next
) {
500 if ( SPACE_SPNUM(spaceCh
) == number
) {
508 unsigned int pa_subspace_start(space
,quadrant
)
509 space_dict_chainS
*space
;
512 if ( (strcasecmp(SPACE_NAME(space
),"$PRIVATE$") == 0) &&
516 else if ( space
->sd_seg
== data_section
&& quadrant
== 1 ) { /* in case name is */
517 /* already converted */
518 /* to a space dict- */
526 int pa_next_subseg(space
)
527 space_dict_chainS
*space
;
530 space
->sd_last_subseg
++;
531 return space
->sd_last_subseg
;
534 int is_last_defined_subspace(ssd
)
535 subspace_dict_chainS
*ssd
;
538 for ( ;ssd
; ssd
= ssd
->ssd_next
) {
539 if ( ssd
->ssd_defined
)
546 symbolS
*pa_get_start_symbol(seg
,subseg
)
550 symbolS
*start_symbol
;
551 subspace_dict_chainS
*ssd
;
555 /* each time a new space is created, build a symbol called LS$START_seg_subseg$ */
556 /* where <space-name> is the name of the space */
557 /* the start symbol will be SS_LOCAL and ST_CODE */
559 if ( seg
== bfd_make_section_old_way ( stdoutput
, ".text" ) ||
560 seg
== bfd_make_section_old_way ( stdoutput
, ".data" ) ||
561 seg
== bfd_make_section_old_way ( stdoutput
, GDB_DEBUG_SPACE_NAME
) ) {
562 ssd
= pa_subsegment_to_subspace(seg
,subseg
);
564 start_symbol
= ssd
->ssd_start_sym
;
567 as_fatal("Internal error: missing subspace for (seg,subseg)=('%s',%d)",
571 as_fatal("Internal error: attempt to find start symbol for unloadable segment: '%s'",
578 Function to define a symbol whose address is the beginning of a subspace.
579 This function assumes the symbol is to be defined for the current subspace.
582 symbolS
*pa_set_start_symbol(seg
,subseg
)
586 symbolS
*start_symbol
;
587 subspace_dict_chainS
*ssd
;
590 symbol_name
= (char *)xmalloc(strlen("LS$START__000000$")+strlen(seg
->name
)+1);
592 sprintf(symbol_name
,"LS$START_%s_%03d$",seg
->name
,subseg
);
595 = symbol_new(symbol_name
,seg
,0,frag_now
); /* XXX: not sure if value s.b. 0 or frag s.b. NULL */
597 start_symbol
->bsym
->flags
= BSF_LOCAL
; /* XXX: isn't there a macro defined for this? */
599 /* each time a new space is created, build a symbol called LS$START_seg_subseg$ */
600 /* where <space-name> is the name of the space */
601 /* the start symbol will be SS_LOCAL and ST_CODE */
602 /* This function assumes that (seg,subseg) is a new subsegment(subspace) */
604 if ( seg
== bfd_make_section_old_way ( stdoutput
, ".text" ) ||
605 seg
== bfd_make_section_old_way ( stdoutput
, ".data" ) ||
606 seg
== bfd_make_section_old_way ( stdoutput
, GDB_DEBUG_SPACE_NAME
) ) {
607 ssd
= pa_subsegment_to_subspace(seg
,subseg
);
609 ssd
->ssd_start_sym
= start_symbol
;
612 as_fatal("Internal error: missing subspace for (seg,subseg)=('%s',%d)",
616 as_fatal("Internal error: attempt to define start symbol for unloadable segment: '%s'",
624 obj_elf_frob_symbol (sym
, punt
)
629 /* If this is a local symbol, are there any relocations for */
630 /* which need this symbol? */
632 /* To find this out, we examine all relocations in all bfd */
633 /* sections that have relocations. If there is one that */
634 /* references this symbol, we need to keep this symbol. In */
635 /* this case, we return a true status. In all other cases, we */
636 /* return a false status. */
638 if ( S_IS_LOCAL(sym
) ) {
639 asymbol
*bsym
= sym
->bsym
;
640 bfd
*abfd
= bsym
->the_bfd
;
643 for ( bsec
= abfd
->sections
; bsec
; bsec
= bsec
->next
) {
644 struct reloc_cache_entry
**rlocs
= bsec
->orelocation
;
645 int rcnt
= bsec
->reloc_count
;
650 for ( i
= 0; i
< rcnt
; i
++ ) {
651 if ( rlocs
[i
]->sym_ptr_ptr
652 && rlocs
[i
]->sym_ptr_ptr
[0] == bsym
)
661 static void obj_elf_line() {
662 /* Assume delimiter is part of expression.
663 BSD4.2 as fails with delightful bug, so we
664 are not being incompatible here. */
665 new_logical_line((char *)NULL
, (int)(get_absolute_expression()));
666 demand_empty_rest_of_line();
667 } /* obj_elf_line() */
672 * Handle .stabX directives, which used to be open-coded.
673 * So much creeping featurism overloaded the semantics that we decided
674 * to put all .stabX thinking in one place. Here.
676 * We try to make any .stabX directive legal. Other people's AS will often
677 * do assembly-time consistency checks: eg assigning meaning to n_type bits
678 * and "protecting" you from setting them to certain values. (They also zero
679 * certain bits before emitting symbols. Tut tut.)
681 * If an expression is not absolute we either gripe or use the relocation
682 * information. Other people's assemblers silently forget information they
683 * don't need and invent information they need that you didn't supply.
685 * .stabX directives always make a symbol table entry. It may be junk if
686 * the rest of your .stabX directive is malformed.
690 * pa_stab_symbol_string()
692 * Build a string dictionary entry for a .stabX symbol.
693 * The symbol is added to the .stabstr section.
697 static unsigned int gdb_string_index
= 0;
700 elf_stab_symbol_string(string
)
707 unsigned int old_gdb_string_index
;
712 old_gdb_string_index
= 0;
713 length
= strlen(string
);
714 clengthP
= (char *)&length
;
715 if ( length
> 0 ) { /* Ordinary case. */
717 save_subseg
= now_subseg
;
719 /* Create the stab sections, if they are not already created. */
720 seg
= bfd_get_section_by_name(stdoutput
,".stabstr");
722 seg
= bfd_make_section_old_way(stdoutput
,".stabstr");
723 bfd_set_section_flags (stdoutput
,
725 SEC_READONLY
| SEC_ALLOC
| SEC_LOAD
);
727 subseg_new((char *) seg
->name
,save_subseg
);
728 old_gdb_string_index
= gdb_string_index
;
730 while ( (c
= *string
++) )
734 FRAG_APPEND_1_CHAR( c
);
737 FRAG_APPEND_1_CHAR( (char)0 );
742 FRAG_APPEND_1_CHAR( (char)0 );
746 subseg_new((char *) save_seg
->name
,save_subseg
);
749 return old_gdb_string_index
;
753 elf_stab_symbol(symbolP
,stab_type
)
762 /* the string index portion of the stab */
764 toP
= frag_more( sizeof(long) +
765 sizeof(S_GET_TYPE(symbolP
)) +
766 sizeof(S_GET_OTHER(symbolP
)) +
767 sizeof(S_GET_DESC(symbolP
)));
768 md_number_to_chars(toP
,symbolP
->sy_name_offset
,sizeof(long));
769 md_number_to_chars(toP
,
771 sizeof(S_GET_TYPE(symbolP
)));
772 md_number_to_chars(toP
+ sizeof(S_GET_TYPE(symbolP
)),
773 S_GET_OTHER(symbolP
),
774 sizeof(S_GET_OTHER(symbolP
)));
775 md_number_to_chars(toP
+ sizeof(S_GET_TYPE(symbolP
))
776 + sizeof(S_GET_OTHER(symbolP
)),
778 sizeof(S_GET_DESC(symbolP
)));
780 /* n_value has to be relocated */
782 /* Don't bother relocating if we're only adding in a constant. */
784 if ((stab_type
== 's' || stab_type
== 'n') && symbolP
->sy_forward
== 0)
785 S_SET_VALUE(symbolP
,S_GET_VALUE(symbolP
->sy_forward
));
788 md_number_to_chars(toP
, S_GET_VALUE(symbolP
),
789 sizeof(S_GET_VALUE(symbolP
)));
792 if ( (stab_type
== 's' || stab_type
== 'n') && symbolP
->sy_forward
)
794 i
= S_GET_TYPE(symbolP
) & N_TYPE
;
795 fix_new_hppa(frag_now
, /* which frag */
796 toP
-frag_now
->fr_literal
, /* where */
798 symbolP
->sy_forward
, /* addr of symbol for this stab */
801 i
== N_UNDF
|| i
== N_ABS
, /* 1 if internal relocation */
802 R_HPPA
, /* reloc type */
803 e_fsel
, /* fixup field = F% */
805 0, /* arg_reloc descriptor */
809 else if ( stab_type
== 'd' )
811 fix_new_hppa (frag_now
, /* which frag */
812 toP
-frag_now
->fr_literal
, /* where */
814 symbolP
, /* addr of symbol for this stab */
818 R_HPPA
, /* reloc type */
819 e_fsel
, /* fixup field = F% */
821 0, /* arg_reloc descriptor */
826 /* What needs to replace the above code? */
831 static void obj_elf_stab(what
)
836 symbolS
* symbolP
= 0;
842 asection
*saved_seg
= now_seg
;
844 subsegT subseg
= now_subseg
;
846 seg
= bfd_get_section_by_name(stdoutput
,".stab");
849 seg
= bfd_make_section_old_way(stdoutput
,".stab");
850 bfd_set_section_flags (stdoutput
,
852 SEC_READONLY
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
);
856 * Enter with input_line_pointer pointing past .stabX and any following
860 string
= demand_copy_C_string(& length
);
862 if (* input_line_pointer
== ',')
863 input_line_pointer
++;
866 as_bad("I need a comma after symbol's name");
874 * Input_line_pointer->after ','. String->symbol name.
878 symbolP
= symbol_new(string
, &bfd_und_section
, 0, (struct frag
*)0);
880 /* enter the string in the .stab string table (section .stabstr) */
881 symbolP
->sy_name_offset
= elf_stab_symbol_string(string
);
886 S_SET_NAME(symbolP
, NULL
); /* .stabd feature. */
887 S_SET_VALUE(symbolP
, obstack_next_free(&frags
) - frag_now
->fr_literal
);
888 S_SET_SEGMENT(symbolP
, now_seg
);
889 symbolP
->sy_frag
= frag_now
;
893 symbolP
->sy_frag
= &zero_address_frag
;
897 symbolP
->sy_frag
= & zero_address_frag
;
905 if (get_absolute_expression_and_terminator(&longint
) == ',')
907 saved_type
= longint
;
908 S_SET_TYPE (symbolP
, saved_type
);
912 as_bad("I want a comma after the n_type expression");
914 input_line_pointer
--; /* Backup over a non-',' char. */
920 if (get_absolute_expression_and_terminator(&longint
) == ',')
921 S_SET_OTHER(symbolP
, longint
);
924 as_bad("I want a comma after the n_other expression");
926 input_line_pointer
--; /* Backup over a non-',' char. */
932 S_SET_DESC(symbolP
, get_absolute_expression());
933 if (what
== 's' || what
== 'n')
935 if (*input_line_pointer
!= ',')
937 as_bad("I want a comma after the n_desc expression");
942 input_line_pointer
++;
948 if ( what
=='s' || what
=='n' ) {
950 S_SET_TYPE (symbolP
, saved_type
);
952 /* Emit the stab symbol. */
953 subseg_new((char *) seg
->name
,subseg
);
954 elf_stab_symbol(symbolP
, what
);
955 subseg_new((char *) saved_seg
->name
,subseg
);
957 if ( what
=='s' || what
=='n' && symbolP
->sy_forward
== NULL
) {
958 /* symbol is not needed in the regular symbol table */
959 symbol_remove(symbolP
,&symbol_rootP
,&symbol_lastP
);
965 if (listing
&& !goof
)
966 switch (S_GET_TYPE (symbolP
))
969 listing_source_line (S_GET_DESC (symbolP
));
973 listing_source_file (string
);
979 ignore_rest_of_line();
981 demand_empty_rest_of_line ();
982 } /* obj_elf_stab() */
984 static void obj_elf_desc() {
992 * Frob invented at RMS' request. Set the n_desc of a symbol.
994 name
= input_line_pointer
;
995 c
= get_symbol_end();
996 p
= input_line_pointer
;
999 if (*input_line_pointer
!= ',') {
1001 as_bad("Expected comma after name \"%s\"", name
);
1003 ignore_rest_of_line();
1005 input_line_pointer
++;
1006 temp
= get_absolute_expression();
1008 symbolP
= symbol_find_or_make(name
);
1010 S_SET_DESC(symbolP
,temp
);
1012 demand_empty_rest_of_line();
1013 } /* obj_elf_desc() */
1015 void obj_read_begin_hook()
1019 void obj_symbol_new_hook(symbolP
)
1022 elf_symbol_type
*esym
= (elf_symbol_type
*)symbolP
;
1024 /* There is an Elf_Internal_Sym and an Elf_External_Sym. For now,
1025 just zero them out. */
1027 bzero((char *) &esym
->internal_elf_sym
,sizeof(Elf_Internal_Sym
));
1028 bzero((char *) &esym
->native_elf_sym
,sizeof(Elf_External_Sym
));
1031 static void obj_elf_version()
1039 asection
*seg
= now_seg
;
1040 subsegT subseg
= now_subseg
;
1041 Elf_Internal_Note i_note
;
1042 Elf_External_Note e_note
;
1043 asection
*note_secp
= (asection
*)NULL
;
1047 if (* input_line_pointer
== '\"') {
1048 ++input_line_pointer
; /* -> 1st char of string. */
1049 name
= input_line_pointer
;
1051 while ( is_a_char(c
= next_char_of_string()) )
1053 c
= *input_line_pointer
;
1054 *input_line_pointer
= '\0';
1055 *(input_line_pointer
-1) = '\0';
1056 *input_line_pointer
= c
;
1058 /* create the .note section if this is the first version string */
1060 note_secp
= bfd_get_section_by_name(stdoutput
,".note");
1061 if ( note_secp
== (asection
*)NULL
) {
1062 note_secp
= bfd_make_section_old_way(stdoutput
,".note");
1063 bfd_set_section_flags(stdoutput
,
1065 SEC_LOAD
| SEC_ALLOC
| SEC_HAS_CONTENTS
);
1068 /* process the version string */
1070 subseg_new((char *)note_secp
->name
, 0);
1073 i_note
.namesz
= ((len
+ 1) + 3) & ~3; /* round this to word boundary */
1074 i_note
.descsz
= 0; /* no description */
1075 i_note
.type
= NT_VERSION
;
1076 p
= frag_more(sizeof(e_note
.namesz
));
1077 md_number_to_chars(p
, i_note
.namesz
, 4);
1078 p
= frag_more(sizeof(e_note
.descsz
));
1079 md_number_to_chars(p
, i_note
.descsz
, 4);
1080 p
= frag_more(sizeof(e_note
.type
));
1081 md_number_to_chars(p
, i_note
.type
, 4);
1083 for ( i
= 0; i
< len
; i
++ ) {
1086 FRAG_APPEND_1_CHAR( ch
);
1091 subseg_new((char *)seg
->name
,subseg
);
1094 as_bad( "Expected \"-ed string" );
1096 demand_empty_rest_of_line();
1102 char *name
= input_line_pointer
;
1103 char c
= get_symbol_end ();
1109 p
= input_line_pointer
;
1112 if (*input_line_pointer
!= ',')
1115 as_bad ("expected comma after name `%s' in .size directive", name
);
1117 ignore_rest_of_line ();
1120 input_line_pointer
++;
1121 sec
= expression (&exp
);
1122 if (sec
== absent_section
)
1124 as_bad ("missing expression in .size directive");
1125 exp
.X_seg
= absolute_section
;
1126 exp
.X_add_number
= 0;
1129 sym
= symbol_find_or_make (name
);
1131 if (sec
== absolute_section
)
1132 S_SET_SIZE (sym
, exp
.X_add_number
);
1134 as_tsktsk (".size not yet supported, ignored");
1135 demand_empty_rest_of_line ();
1141 char *name
= input_line_pointer
;
1142 char c
= get_symbol_end ();
1147 p
= input_line_pointer
;
1150 if (*input_line_pointer
!= ',')
1152 as_bad ("expected comma after name in .type directive");
1154 ignore_rest_of_line ();
1157 input_line_pointer
++;
1159 if (*input_line_pointer
!= '#')
1161 as_bad ("expected `#' after comma in .type directive");
1164 input_line_pointer
++;
1165 if (!strncmp ("function", input_line_pointer
, sizeof ("function") - 1))
1167 type
= BSF_FUNCTION
;
1168 input_line_pointer
+= sizeof ("function") - 1;
1172 as_bad ("unrecognized symbol type, ignored");
1175 demand_empty_rest_of_line ();
1177 sym
= symbol_find_or_make (name
);
1178 sym
->bsym
->flags
= type
;
1187 string
= demand_copy_C_string (&xxx
);
1188 as_tsktsk (".ident not supported, ignoring");