tc-ppc.c revision 89857
1219820Sjeff/* tc-ppc.c -- Assemble for the PowerPC or POWER (RS/6000) 2219820Sjeff Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 3219820Sjeff Free Software Foundation, Inc. 4219820Sjeff Written by Ian Lance Taylor, Cygnus Support. 5219820Sjeff 6219820Sjeff This file is part of GAS, the GNU Assembler. 7219820Sjeff 8219820Sjeff GAS is free software; you can redistribute it and/or modify 9219820Sjeff it under the terms of the GNU General Public License as published by 10219820Sjeff the Free Software Foundation; either version 2, or (at your option) 11219820Sjeff any later version. 12219820Sjeff 13219820Sjeff GAS is distributed in the hope that it will be useful, 14219820Sjeff but WITHOUT ANY WARRANTY; without even the implied warranty of 15219820Sjeff MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with GAS; see the file COPYING. If not, write to the Free 20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 21 02111-1307, USA. */ 22 23#include <stdio.h> 24#include "as.h" 25#include "safe-ctype.h" 26#include "subsegs.h" 27 28#include "opcode/ppc.h" 29 30#ifdef OBJ_ELF 31#include "elf/ppc.h" 32#include "dwarf2dbg.h" 33#endif 34 35#ifdef TE_PE 36#include "coff/pe.h" 37#endif 38 39/* This is the assembler for the PowerPC or POWER (RS/6000) chips. */ 40 41/* Tell the main code what the endianness is. */ 42extern int target_big_endian; 43 44/* Whether or not, we've set target_big_endian. */ 45static int set_target_endian = 0; 46 47/* Whether to use user friendly register names. */ 48#ifndef TARGET_REG_NAMES_P 49#ifdef TE_PE 50#define TARGET_REG_NAMES_P true 51#else 52#define TARGET_REG_NAMES_P false 53#endif 54#endif 55 56/* Macros for calculating LO, HI, HA, HIGHER, HIGHERA, HIGHEST, 57 HIGHESTA. */ 58 59/* #lo(value) denotes the least significant 16 bits of the indicated. */ 60#define PPC_LO(v) ((v) & 0xffff) 61 62/* #hi(value) denotes bits 16 through 31 of the indicated value. */ 63#define PPC_HI(v) (((v) >> 16) & 0xffff) 64 65/* #ha(value) denotes the high adjusted value: bits 16 through 31 of 66 the indicated value, compensating for #lo() being treated as a 67 signed number. */ 68#define PPC_HA(v) PPC_HI ((v) + 0x8000) 69 70/* #higher(value) denotes bits 32 through 47 of the indicated value. */ 71#define PPC_HIGHER(v) (((v) >> 32) & 0xffff) 72 73/* #highera(value) denotes bits 32 through 47 of the indicated value, 74 compensating for #lo() being treated as a signed number. */ 75#define PPC_HIGHERA(v) PPC_HIGHER ((v) + 0x8000) 76 77/* #highest(value) denotes bits 48 through 63 of the indicated value. */ 78#define PPC_HIGHEST(v) (((v) >> 48) & 0xffff) 79 80/* #highesta(value) denotes bits 48 through 63 of the indicated value, 81 compensating for #lo being treated as a signed number. */ 82#define PPC_HIGHESTA(v) PPC_HIGHEST ((v) + 0x8000) 83 84#define SEX16(val) ((((val) & 0xffff) ^ 0x8000) - 0x8000) 85 86static boolean reg_names_p = TARGET_REG_NAMES_P; 87 88static boolean register_name PARAMS ((expressionS *)); 89static void ppc_set_cpu PARAMS ((void)); 90static unsigned long ppc_insert_operand 91 PARAMS ((unsigned long insn, const struct powerpc_operand *operand, 92 offsetT val, char *file, unsigned int line)); 93static void ppc_macro PARAMS ((char *str, const struct powerpc_macro *macro)); 94static void ppc_byte PARAMS ((int)); 95 96#if defined (OBJ_XCOFF) || defined (OBJ_ELF) 97static int ppc_is_toc_sym PARAMS ((symbolS *sym)); 98static void ppc_tc PARAMS ((int)); 99static void ppc_machine PARAMS ((int)); 100#endif 101 102#ifdef OBJ_XCOFF 103static void ppc_comm PARAMS ((int)); 104static void ppc_bb PARAMS ((int)); 105static void ppc_bc PARAMS ((int)); 106static void ppc_bf PARAMS ((int)); 107static void ppc_biei PARAMS ((int)); 108static void ppc_bs PARAMS ((int)); 109static void ppc_eb PARAMS ((int)); 110static void ppc_ec PARAMS ((int)); 111static void ppc_ef PARAMS ((int)); 112static void ppc_es PARAMS ((int)); 113static void ppc_csect PARAMS ((int)); 114static void ppc_change_csect PARAMS ((symbolS *)); 115static void ppc_function PARAMS ((int)); 116static void ppc_extern PARAMS ((int)); 117static void ppc_lglobl PARAMS ((int)); 118static void ppc_section PARAMS ((int)); 119static void ppc_named_section PARAMS ((int)); 120static void ppc_stabx PARAMS ((int)); 121static void ppc_rename PARAMS ((int)); 122static void ppc_toc PARAMS ((int)); 123static void ppc_xcoff_cons PARAMS ((int)); 124static void ppc_vbyte PARAMS ((int)); 125#endif 126 127#ifdef OBJ_ELF 128static bfd_reloc_code_real_type ppc_elf_suffix PARAMS ((char **, expressionS *)); 129static void ppc_elf_cons PARAMS ((int)); 130static void ppc_elf_rdata PARAMS ((int)); 131static void ppc_elf_lcomm PARAMS ((int)); 132static void ppc_elf_validate_fix PARAMS ((fixS *, segT)); 133#endif 134 135#ifdef TE_PE 136static void ppc_set_current_section PARAMS ((segT)); 137static void ppc_previous PARAMS ((int)); 138static void ppc_pdata PARAMS ((int)); 139static void ppc_ydata PARAMS ((int)); 140static void ppc_reldata PARAMS ((int)); 141static void ppc_rdata PARAMS ((int)); 142static void ppc_ualong PARAMS ((int)); 143static void ppc_znop PARAMS ((int)); 144static void ppc_pe_comm PARAMS ((int)); 145static void ppc_pe_section PARAMS ((int)); 146static void ppc_pe_function PARAMS ((int)); 147static void ppc_pe_tocd PARAMS ((int)); 148#endif 149 150/* Generic assembler global variables which must be defined by all 151 targets. */ 152 153#ifdef OBJ_ELF 154/* This string holds the chars that always start a comment. If the 155 pre-processor is disabled, these aren't very useful. The macro 156 tc_comment_chars points to this. We use this, rather than the 157 usual comment_chars, so that we can switch for Solaris conventions. */ 158static const char ppc_solaris_comment_chars[] = "#!"; 159static const char ppc_eabi_comment_chars[] = "#"; 160 161#ifdef TARGET_SOLARIS_COMMENT 162const char *ppc_comment_chars = ppc_solaris_comment_chars; 163#else 164const char *ppc_comment_chars = ppc_eabi_comment_chars; 165#endif 166#else 167const char comment_chars[] = "#"; 168#endif 169 170/* Characters which start a comment at the beginning of a line. */ 171const char line_comment_chars[] = "#"; 172 173/* Characters which may be used to separate multiple commands on a 174 single line. */ 175const char line_separator_chars[] = ";"; 176 177/* Characters which are used to indicate an exponent in a floating 178 point number. */ 179const char EXP_CHARS[] = "eE"; 180 181/* Characters which mean that a number is a floating point constant, 182 as in 0d1.0. */ 183const char FLT_CHARS[] = "dD"; 184 185/* The target specific pseudo-ops which we support. */ 186 187const pseudo_typeS md_pseudo_table[] = 188{ 189 /* Pseudo-ops which must be overridden. */ 190 { "byte", ppc_byte, 0 }, 191 192#ifdef OBJ_XCOFF 193 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these 194 legitimately belong in the obj-*.c file. However, XCOFF is based 195 on COFF, and is only implemented for the RS/6000. We just use 196 obj-coff.c, and add what we need here. */ 197 { "comm", ppc_comm, 0 }, 198 { "lcomm", ppc_comm, 1 }, 199 { "bb", ppc_bb, 0 }, 200 { "bc", ppc_bc, 0 }, 201 { "bf", ppc_bf, 0 }, 202 { "bi", ppc_biei, 0 }, 203 { "bs", ppc_bs, 0 }, 204 { "csect", ppc_csect, 0 }, 205 { "data", ppc_section, 'd' }, 206 { "eb", ppc_eb, 0 }, 207 { "ec", ppc_ec, 0 }, 208 { "ef", ppc_ef, 0 }, 209 { "ei", ppc_biei, 1 }, 210 { "es", ppc_es, 0 }, 211 { "extern", ppc_extern, 0 }, 212 { "function", ppc_function, 0 }, 213 { "lglobl", ppc_lglobl, 0 }, 214 { "rename", ppc_rename, 0 }, 215 { "section", ppc_named_section, 0 }, 216 { "stabx", ppc_stabx, 0 }, 217 { "text", ppc_section, 't' }, 218 { "toc", ppc_toc, 0 }, 219 { "long", ppc_xcoff_cons, 2 }, 220 { "llong", ppc_xcoff_cons, 3 }, 221 { "word", ppc_xcoff_cons, 1 }, 222 { "short", ppc_xcoff_cons, 1 }, 223 { "vbyte", ppc_vbyte, 0 }, 224#endif 225 226#ifdef OBJ_ELF 227 { "llong", ppc_elf_cons, 8 }, 228 { "quad", ppc_elf_cons, 8 }, 229 { "long", ppc_elf_cons, 4 }, 230 { "word", ppc_elf_cons, 2 }, 231 { "short", ppc_elf_cons, 2 }, 232 { "rdata", ppc_elf_rdata, 0 }, 233 { "rodata", ppc_elf_rdata, 0 }, 234 { "lcomm", ppc_elf_lcomm, 0 }, 235 { "file", dwarf2_directive_file, 0 }, 236 { "loc", dwarf2_directive_loc, 0 }, 237#endif 238 239#ifdef TE_PE 240 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format. */ 241 { "previous", ppc_previous, 0 }, 242 { "pdata", ppc_pdata, 0 }, 243 { "ydata", ppc_ydata, 0 }, 244 { "reldata", ppc_reldata, 0 }, 245 { "rdata", ppc_rdata, 0 }, 246 { "ualong", ppc_ualong, 0 }, 247 { "znop", ppc_znop, 0 }, 248 { "comm", ppc_pe_comm, 0 }, 249 { "lcomm", ppc_pe_comm, 1 }, 250 { "section", ppc_pe_section, 0 }, 251 { "function", ppc_pe_function,0 }, 252 { "tocd", ppc_pe_tocd, 0 }, 253#endif 254 255#if defined (OBJ_XCOFF) || defined (OBJ_ELF) 256 { "tc", ppc_tc, 0 }, 257 { "machine", ppc_machine, 0 }, 258#endif 259 260 { NULL, NULL, 0 } 261}; 262 263 264/* Predefined register names if -mregnames (or default for Windows NT). 265 In general, there are lots of them, in an attempt to be compatible 266 with a number of other Windows NT assemblers. */ 267 268/* Structure to hold information about predefined registers. */ 269struct pd_reg 270 { 271 char *name; 272 int value; 273 }; 274 275/* List of registers that are pre-defined: 276 277 Each general register has predefined names of the form: 278 1. r<reg_num> which has the value <reg_num>. 279 2. r.<reg_num> which has the value <reg_num>. 280 281 Each floating point register has predefined names of the form: 282 1. f<reg_num> which has the value <reg_num>. 283 2. f.<reg_num> which has the value <reg_num>. 284 285 Each vector unit register has predefined names of the form: 286 1. v<reg_num> which has the value <reg_num>. 287 2. v.<reg_num> which has the value <reg_num>. 288 289 Each condition register has predefined names of the form: 290 1. cr<reg_num> which has the value <reg_num>. 291 2. cr.<reg_num> which has the value <reg_num>. 292 293 There are individual registers as well: 294 sp or r.sp has the value 1 295 rtoc or r.toc has the value 2 296 fpscr has the value 0 297 xer has the value 1 298 lr has the value 8 299 ctr has the value 9 300 pmr has the value 0 301 dar has the value 19 302 dsisr has the value 18 303 dec has the value 22 304 sdr1 has the value 25 305 srr0 has the value 26 306 srr1 has the value 27 307 308 The table is sorted. Suitable for searching by a binary search. */ 309 310static const struct pd_reg pre_defined_registers[] = 311{ 312 { "cr.0", 0 }, /* Condition Registers */ 313 { "cr.1", 1 }, 314 { "cr.2", 2 }, 315 { "cr.3", 3 }, 316 { "cr.4", 4 }, 317 { "cr.5", 5 }, 318 { "cr.6", 6 }, 319 { "cr.7", 7 }, 320 321 { "cr0", 0 }, 322 { "cr1", 1 }, 323 { "cr2", 2 }, 324 { "cr3", 3 }, 325 { "cr4", 4 }, 326 { "cr5", 5 }, 327 { "cr6", 6 }, 328 { "cr7", 7 }, 329 330 { "ctr", 9 }, 331 332 { "dar", 19 }, /* Data Access Register */ 333 { "dec", 22 }, /* Decrementer */ 334 { "dsisr", 18 }, /* Data Storage Interrupt Status Register */ 335 336 { "f.0", 0 }, /* Floating point registers */ 337 { "f.1", 1 }, 338 { "f.10", 10 }, 339 { "f.11", 11 }, 340 { "f.12", 12 }, 341 { "f.13", 13 }, 342 { "f.14", 14 }, 343 { "f.15", 15 }, 344 { "f.16", 16 }, 345 { "f.17", 17 }, 346 { "f.18", 18 }, 347 { "f.19", 19 }, 348 { "f.2", 2 }, 349 { "f.20", 20 }, 350 { "f.21", 21 }, 351 { "f.22", 22 }, 352 { "f.23", 23 }, 353 { "f.24", 24 }, 354 { "f.25", 25 }, 355 { "f.26", 26 }, 356 { "f.27", 27 }, 357 { "f.28", 28 }, 358 { "f.29", 29 }, 359 { "f.3", 3 }, 360 { "f.30", 30 }, 361 { "f.31", 31 }, 362 { "f.4", 4 }, 363 { "f.5", 5 }, 364 { "f.6", 6 }, 365 { "f.7", 7 }, 366 { "f.8", 8 }, 367 { "f.9", 9 }, 368 369 { "f0", 0 }, 370 { "f1", 1 }, 371 { "f10", 10 }, 372 { "f11", 11 }, 373 { "f12", 12 }, 374 { "f13", 13 }, 375 { "f14", 14 }, 376 { "f15", 15 }, 377 { "f16", 16 }, 378 { "f17", 17 }, 379 { "f18", 18 }, 380 { "f19", 19 }, 381 { "f2", 2 }, 382 { "f20", 20 }, 383 { "f21", 21 }, 384 { "f22", 22 }, 385 { "f23", 23 }, 386 { "f24", 24 }, 387 { "f25", 25 }, 388 { "f26", 26 }, 389 { "f27", 27 }, 390 { "f28", 28 }, 391 { "f29", 29 }, 392 { "f3", 3 }, 393 { "f30", 30 }, 394 { "f31", 31 }, 395 { "f4", 4 }, 396 { "f5", 5 }, 397 { "f6", 6 }, 398 { "f7", 7 }, 399 { "f8", 8 }, 400 { "f9", 9 }, 401 402 { "fpscr", 0 }, 403 404 { "lr", 8 }, /* Link Register */ 405 406 { "pmr", 0 }, 407 408 { "r.0", 0 }, /* General Purpose Registers */ 409 { "r.1", 1 }, 410 { "r.10", 10 }, 411 { "r.11", 11 }, 412 { "r.12", 12 }, 413 { "r.13", 13 }, 414 { "r.14", 14 }, 415 { "r.15", 15 }, 416 { "r.16", 16 }, 417 { "r.17", 17 }, 418 { "r.18", 18 }, 419 { "r.19", 19 }, 420 { "r.2", 2 }, 421 { "r.20", 20 }, 422 { "r.21", 21 }, 423 { "r.22", 22 }, 424 { "r.23", 23 }, 425 { "r.24", 24 }, 426 { "r.25", 25 }, 427 { "r.26", 26 }, 428 { "r.27", 27 }, 429 { "r.28", 28 }, 430 { "r.29", 29 }, 431 { "r.3", 3 }, 432 { "r.30", 30 }, 433 { "r.31", 31 }, 434 { "r.4", 4 }, 435 { "r.5", 5 }, 436 { "r.6", 6 }, 437 { "r.7", 7 }, 438 { "r.8", 8 }, 439 { "r.9", 9 }, 440 441 { "r.sp", 1 }, /* Stack Pointer */ 442 443 { "r.toc", 2 }, /* Pointer to the table of contents */ 444 445 { "r0", 0 }, /* More general purpose registers */ 446 { "r1", 1 }, 447 { "r10", 10 }, 448 { "r11", 11 }, 449 { "r12", 12 }, 450 { "r13", 13 }, 451 { "r14", 14 }, 452 { "r15", 15 }, 453 { "r16", 16 }, 454 { "r17", 17 }, 455 { "r18", 18 }, 456 { "r19", 19 }, 457 { "r2", 2 }, 458 { "r20", 20 }, 459 { "r21", 21 }, 460 { "r22", 22 }, 461 { "r23", 23 }, 462 { "r24", 24 }, 463 { "r25", 25 }, 464 { "r26", 26 }, 465 { "r27", 27 }, 466 { "r28", 28 }, 467 { "r29", 29 }, 468 { "r3", 3 }, 469 { "r30", 30 }, 470 { "r31", 31 }, 471 { "r4", 4 }, 472 { "r5", 5 }, 473 { "r6", 6 }, 474 { "r7", 7 }, 475 { "r8", 8 }, 476 { "r9", 9 }, 477 478 { "rtoc", 2 }, /* Table of contents */ 479 480 { "sdr1", 25 }, /* Storage Description Register 1 */ 481 482 { "sp", 1 }, 483 484 { "srr0", 26 }, /* Machine Status Save/Restore Register 0 */ 485 { "srr1", 27 }, /* Machine Status Save/Restore Register 1 */ 486 487 { "v.0", 0 }, /* Vector registers */ 488 { "v.1", 1 }, 489 { "v.10", 10 }, 490 { "v.11", 11 }, 491 { "v.12", 12 }, 492 { "v.13", 13 }, 493 { "v.14", 14 }, 494 { "v.15", 15 }, 495 { "v.16", 16 }, 496 { "v.17", 17 }, 497 { "v.18", 18 }, 498 { "v.19", 19 }, 499 { "v.2", 2 }, 500 { "v.20", 20 }, 501 { "v.21", 21 }, 502 { "v.22", 22 }, 503 { "v.23", 23 }, 504 { "v.24", 24 }, 505 { "v.25", 25 }, 506 { "v.26", 26 }, 507 { "v.27", 27 }, 508 { "v.28", 28 }, 509 { "v.29", 29 }, 510 { "v.3", 3 }, 511 { "v.30", 30 }, 512 { "v.31", 31 }, 513 { "v.4", 4 }, 514 { "v.5", 5 }, 515 { "v.6", 6 }, 516 { "v.7", 7 }, 517 { "v.8", 8 }, 518 { "v.9", 9 }, 519 520 { "v0", 0 }, 521 { "v1", 1 }, 522 { "v10", 10 }, 523 { "v11", 11 }, 524 { "v12", 12 }, 525 { "v13", 13 }, 526 { "v14", 14 }, 527 { "v15", 15 }, 528 { "v16", 16 }, 529 { "v17", 17 }, 530 { "v18", 18 }, 531 { "v19", 19 }, 532 { "v2", 2 }, 533 { "v20", 20 }, 534 { "v21", 21 }, 535 { "v22", 22 }, 536 { "v23", 23 }, 537 { "v24", 24 }, 538 { "v25", 25 }, 539 { "v26", 26 }, 540 { "v27", 27 }, 541 { "v28", 28 }, 542 { "v29", 29 }, 543 { "v3", 3 }, 544 { "v30", 30 }, 545 { "v31", 31 }, 546 { "v4", 4 }, 547 { "v5", 5 }, 548 { "v6", 6 }, 549 { "v7", 7 }, 550 { "v8", 8 }, 551 { "v9", 9 }, 552 553 { "xer", 1 }, 554 555}; 556 557#define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct pd_reg)) 558 559/* Given NAME, find the register number associated with that name, return 560 the integer value associated with the given name or -1 on failure. */ 561 562static int reg_name_search 563 PARAMS ((const struct pd_reg *, int, const char * name)); 564 565static int 566reg_name_search (regs, regcount, name) 567 const struct pd_reg *regs; 568 int regcount; 569 const char *name; 570{ 571 int middle, low, high; 572 int cmp; 573 574 low = 0; 575 high = regcount - 1; 576 577 do 578 { 579 middle = (low + high) / 2; 580 cmp = strcasecmp (name, regs[middle].name); 581 if (cmp < 0) 582 high = middle - 1; 583 else if (cmp > 0) 584 low = middle + 1; 585 else 586 return regs[middle].value; 587 } 588 while (low <= high); 589 590 return -1; 591} 592 593/* 594 * Summary of register_name. 595 * 596 * in: Input_line_pointer points to 1st char of operand. 597 * 598 * out: A expressionS. 599 * The operand may have been a register: in this case, X_op == O_register, 600 * X_add_number is set to the register number, and truth is returned. 601 * Input_line_pointer->(next non-blank) char after operand, or is in its 602 * original state. 603 */ 604 605static boolean 606register_name (expressionP) 607 expressionS *expressionP; 608{ 609 int reg_number; 610 char *name; 611 char *start; 612 char c; 613 614 /* Find the spelling of the operand. */ 615 start = name = input_line_pointer; 616 if (name[0] == '%' && ISALPHA (name[1])) 617 name = ++input_line_pointer; 618 619 else if (!reg_names_p || !ISALPHA (name[0])) 620 return false; 621 622 c = get_symbol_end (); 623 reg_number = reg_name_search (pre_defined_registers, REG_NAME_CNT, name); 624 625 /* Put back the delimiting char. */ 626 *input_line_pointer = c; 627 628 /* Look to see if it's in the register table. */ 629 if (reg_number >= 0) 630 { 631 expressionP->X_op = O_register; 632 expressionP->X_add_number = reg_number; 633 634 /* Make the rest nice. */ 635 expressionP->X_add_symbol = NULL; 636 expressionP->X_op_symbol = NULL; 637 return true; 638 } 639 640 /* Reset the line as if we had not done anything. */ 641 input_line_pointer = start; 642 return false; 643} 644 645/* This function is called for each symbol seen in an expression. It 646 handles the special parsing which PowerPC assemblers are supposed 647 to use for condition codes. */ 648 649/* Whether to do the special parsing. */ 650static boolean cr_operand; 651 652/* Names to recognize in a condition code. This table is sorted. */ 653static const struct pd_reg cr_names[] = 654{ 655 { "cr0", 0 }, 656 { "cr1", 1 }, 657 { "cr2", 2 }, 658 { "cr3", 3 }, 659 { "cr4", 4 }, 660 { "cr5", 5 }, 661 { "cr6", 6 }, 662 { "cr7", 7 }, 663 { "eq", 2 }, 664 { "gt", 1 }, 665 { "lt", 0 }, 666 { "so", 3 }, 667 { "un", 3 } 668}; 669 670/* Parsing function. This returns non-zero if it recognized an 671 expression. */ 672 673int 674ppc_parse_name (name, expr) 675 const char *name; 676 expressionS *expr; 677{ 678 int val; 679 680 if (! cr_operand) 681 return 0; 682 683 val = reg_name_search (cr_names, sizeof cr_names / sizeof cr_names[0], 684 name); 685 if (val < 0) 686 return 0; 687 688 expr->X_op = O_constant; 689 expr->X_add_number = val; 690 691 return 1; 692} 693 694/* Local variables. */ 695 696/* The type of processor we are assembling for. This is one or more 697 of the PPC_OPCODE flags defined in opcode/ppc.h. */ 698static int ppc_cpu = 0; 699 700/* The size of the processor we are assembling for. This is either 701 PPC_OPCODE_32 or PPC_OPCODE_64. */ 702static unsigned long ppc_size = (BFD_DEFAULT_TARGET_SIZE == 64 703 ? PPC_OPCODE_64 704 : PPC_OPCODE_32); 705 706/* Whether to target xcoff64. */ 707static int ppc_xcoff64 = 0; 708 709/* Opcode hash table. */ 710static struct hash_control *ppc_hash; 711 712/* Macro hash table. */ 713static struct hash_control *ppc_macro_hash; 714 715#ifdef OBJ_ELF 716/* What type of shared library support to use. */ 717static enum { SHLIB_NONE, SHLIB_PIC, SHLIB_MRELOCATABLE } shlib = SHLIB_NONE; 718 719/* Flags to set in the elf header. */ 720static flagword ppc_flags = 0; 721 722/* Whether this is Solaris or not. */ 723#ifdef TARGET_SOLARIS_COMMENT 724#define SOLARIS_P true 725#else 726#define SOLARIS_P false 727#endif 728 729static boolean msolaris = SOLARIS_P; 730#endif 731 732#ifdef OBJ_XCOFF 733 734/* The RS/6000 assembler uses the .csect pseudo-op to generate code 735 using a bunch of different sections. These assembler sections, 736 however, are all encompassed within the .text or .data sections of 737 the final output file. We handle this by using different 738 subsegments within these main segments. */ 739 740/* Next subsegment to allocate within the .text segment. */ 741static subsegT ppc_text_subsegment = 2; 742 743/* Linked list of csects in the text section. */ 744static symbolS *ppc_text_csects; 745 746/* Next subsegment to allocate within the .data segment. */ 747static subsegT ppc_data_subsegment = 2; 748 749/* Linked list of csects in the data section. */ 750static symbolS *ppc_data_csects; 751 752/* The current csect. */ 753static symbolS *ppc_current_csect; 754 755/* The RS/6000 assembler uses a TOC which holds addresses of functions 756 and variables. Symbols are put in the TOC with the .tc pseudo-op. 757 A special relocation is used when accessing TOC entries. We handle 758 the TOC as a subsegment within the .data segment. We set it up if 759 we see a .toc pseudo-op, and save the csect symbol here. */ 760static symbolS *ppc_toc_csect; 761 762/* The first frag in the TOC subsegment. */ 763static fragS *ppc_toc_frag; 764 765/* The first frag in the first subsegment after the TOC in the .data 766 segment. NULL if there are no subsegments after the TOC. */ 767static fragS *ppc_after_toc_frag; 768 769/* The current static block. */ 770static symbolS *ppc_current_block; 771 772/* The COFF debugging section; set by md_begin. This is not the 773 .debug section, but is instead the secret BFD section which will 774 cause BFD to set the section number of a symbol to N_DEBUG. */ 775static asection *ppc_coff_debug_section; 776 777#endif /* OBJ_XCOFF */ 778 779#ifdef TE_PE 780 781/* Various sections that we need for PE coff support. */ 782static segT ydata_section; 783static segT pdata_section; 784static segT reldata_section; 785static segT rdata_section; 786static segT tocdata_section; 787 788/* The current section and the previous section. See ppc_previous. */ 789static segT ppc_previous_section; 790static segT ppc_current_section; 791 792#endif /* TE_PE */ 793 794#ifdef OBJ_ELF 795symbolS *GOT_symbol; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */ 796#endif /* OBJ_ELF */ 797 798#ifdef OBJ_ELF 799const char *const md_shortopts = "b:l:usm:K:VQ:"; 800#else 801const char *const md_shortopts = "um:"; 802#endif 803const struct option md_longopts[] = { 804 {NULL, no_argument, NULL, 0} 805}; 806const size_t md_longopts_size = sizeof (md_longopts); 807 808int 809md_parse_option (c, arg) 810 int c; 811 char *arg; 812{ 813 switch (c) 814 { 815 case 'u': 816 /* -u means that any undefined symbols should be treated as 817 external, which is the default for gas anyhow. */ 818 break; 819 820#ifdef OBJ_ELF 821 case 'l': 822 /* Solaris as takes -le (presumably for little endian). For completeness 823 sake, recognize -be also. */ 824 if (strcmp (arg, "e") == 0) 825 { 826 target_big_endian = 0; 827 set_target_endian = 1; 828 } 829 else 830 return 0; 831 832 break; 833 834 case 'b': 835 if (strcmp (arg, "e") == 0) 836 { 837 target_big_endian = 1; 838 set_target_endian = 1; 839 } 840 else 841 return 0; 842 843 break; 844 845 case 'K': 846 /* Recognize -K PIC. */ 847 if (strcmp (arg, "PIC") == 0 || strcmp (arg, "pic") == 0) 848 { 849 shlib = SHLIB_PIC; 850 ppc_flags |= EF_PPC_RELOCATABLE_LIB; 851 } 852 else 853 return 0; 854 855 break; 856#endif 857 858 /* a64 and a32 determine whether to use XCOFF64 or XCOFF32. */ 859 case 'a': 860 if (strcmp (arg, "64") == 0) 861 ppc_xcoff64 = 1; 862 else if (strcmp (arg, "32") == 0) 863 ppc_xcoff64 = 0; 864 else 865 return 0; 866 break; 867 868 case 'm': 869 /* Most CPU's are 32 bit. Exceptions are listed below. */ 870 ppc_size = PPC_OPCODE_32; 871 872 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2 873 (RIOS2). */ 874 if (strcmp (arg, "pwrx") == 0 || strcmp (arg, "pwr2") == 0) 875 ppc_cpu = PPC_OPCODE_POWER | PPC_OPCODE_POWER2; 876 /* -mpwr means to assemble for the IBM POWER (RIOS1). */ 877 else if (strcmp (arg, "pwr") == 0) 878 ppc_cpu = PPC_OPCODE_POWER; 879 /* -m601 means to assemble for the Motorola PowerPC 601, which includes 880 instructions that are holdovers from the Power. */ 881 else if (strcmp (arg, "601") == 0) 882 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_601; 883 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the 884 Motorola PowerPC 603/604. */ 885 else if (strcmp (arg, "ppc") == 0 886 || strcmp (arg, "ppc32") == 0 887 || strcmp (arg, "603") == 0 888 || strcmp (arg, "604") == 0) 889 ppc_cpu = PPC_OPCODE_PPC; 890 /* -m403 and -m405 mean to assemble for the Motorola PowerPC 403/405. */ 891 else if (strcmp (arg, "403") == 0 892 || strcmp (arg, "405") == 0) 893 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_403; 894 else if (strcmp (arg, "7400") == 0 895 || strcmp (arg, "7410") == 0 896 || strcmp (arg, "7450") == 0 897 || strcmp (arg, "7455") == 0) 898 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_ALTIVEC; 899 else if (strcmp (arg, "altivec") == 0) 900 { 901 if (ppc_cpu == 0) 902 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_ALTIVEC; 903 else 904 ppc_cpu |= PPC_OPCODE_ALTIVEC; 905 } 906 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC 907 620. */ 908 else if (strcmp (arg, "ppc64") == 0 || strcmp (arg, "620") == 0) 909 { 910 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_64; 911 ppc_size = PPC_OPCODE_64; 912 } 913 else if (strcmp (arg, "ppc64bridge") == 0) 914 { 915 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_64_BRIDGE | PPC_OPCODE_64; 916 ppc_size = PPC_OPCODE_64; 917 } 918 /* -mbooke/-mbooke32 mean enable 32-bit BookE support. */ 919 else if (strcmp (arg, "booke") == 0 || strcmp (arg, "booke32") == 0) 920 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_BOOKE; 921 /* -mbooke64 means enable 64-bit BookE support. */ 922 else if (strcmp (arg, "booke64") == 0) 923 { 924 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_BOOKE | 925 PPC_OPCODE_BOOKE64 | PPC_OPCODE_64; 926 ppc_size = PPC_OPCODE_64; 927 } 928 /* -mcom means assemble for the common intersection between Power 929 and PowerPC. At present, we just allow the union, rather 930 than the intersection. */ 931 else if (strcmp (arg, "com") == 0) 932 ppc_cpu = PPC_OPCODE_COMMON; 933 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */ 934 else if (strcmp (arg, "any") == 0) 935 ppc_cpu = PPC_OPCODE_ANY; 936 937 else if (strcmp (arg, "regnames") == 0) 938 reg_names_p = true; 939 940 else if (strcmp (arg, "no-regnames") == 0) 941 reg_names_p = false; 942 943#ifdef OBJ_ELF 944 /* -mrelocatable/-mrelocatable-lib -- warn about initializations 945 that require relocation. */ 946 else if (strcmp (arg, "relocatable") == 0) 947 { 948 shlib = SHLIB_MRELOCATABLE; 949 ppc_flags |= EF_PPC_RELOCATABLE; 950 } 951 952 else if (strcmp (arg, "relocatable-lib") == 0) 953 { 954 shlib = SHLIB_MRELOCATABLE; 955 ppc_flags |= EF_PPC_RELOCATABLE_LIB; 956 } 957 958 /* -memb, set embedded bit. */ 959 else if (strcmp (arg, "emb") == 0) 960 ppc_flags |= EF_PPC_EMB; 961 962 /* -mlittle/-mbig set the endianess. */ 963 else if (strcmp (arg, "little") == 0 964 || strcmp (arg, "little-endian") == 0) 965 { 966 target_big_endian = 0; 967 set_target_endian = 1; 968 } 969 970 else if (strcmp (arg, "big") == 0 || strcmp (arg, "big-endian") == 0) 971 { 972 target_big_endian = 1; 973 set_target_endian = 1; 974 } 975 976 else if (strcmp (arg, "solaris") == 0) 977 { 978 msolaris = true; 979 ppc_comment_chars = ppc_solaris_comment_chars; 980 } 981 982 else if (strcmp (arg, "no-solaris") == 0) 983 { 984 msolaris = false; 985 ppc_comment_chars = ppc_eabi_comment_chars; 986 } 987#endif 988 else 989 { 990 as_bad (_("invalid switch -m%s"), arg); 991 return 0; 992 } 993 break; 994 995#ifdef OBJ_ELF 996 /* -V: SVR4 argument to print version ID. */ 997 case 'V': 998 print_version_id (); 999 break; 1000 1001 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section 1002 should be emitted or not. FIXME: Not implemented. */ 1003 case 'Q': 1004 break; 1005 1006 /* Solaris takes -s to specify that .stabs go in a .stabs section, 1007 rather than .stabs.excl, which is ignored by the linker. 1008 FIXME: Not implemented. */ 1009 case 's': 1010 if (arg) 1011 return 0; 1012 1013 break; 1014#endif 1015 1016 default: 1017 return 0; 1018 } 1019 1020 return 1; 1021} 1022 1023void 1024md_show_usage (stream) 1025 FILE *stream; 1026{ 1027 fprintf (stream, _("\ 1028PowerPC options:\n\ 1029-u ignored\n\ 1030-mpwrx, -mpwr2 generate code for IBM POWER/2 (RIOS2)\n\ 1031-mpwr generate code for IBM POWER (RIOS1)\n\ 1032-m601 generate code for Motorola PowerPC 601\n\ 1033-mppc, -mppc32, -m603, -m604\n\ 1034 generate code for Motorola PowerPC 603/604\n\ 1035-m403, -m405 generate code for Motorola PowerPC 403/405\n\ 1036-m7400, -m7410, -m7450, -m7455\n\ 1037 generate code For Motorola PowerPC 7400/7410/7450/7455\n\ 1038-mppc64, -m620 generate code for Motorola PowerPC 620\n\ 1039-mppc64bridge generate code for PowerPC 64, including bridge insns\n\ 1040-mbooke64 generate code for 64-bit PowerPC BookE\n\ 1041-mbooke, mbooke32 generate code for 32-bit PowerPC BookE\n\ 1042-maltivec generate code for AltiVec\n\ 1043-mcom generate code Power/PowerPC common instructions\n\ 1044-many generate code for any architecture (PWR/PWRX/PPC)\n\ 1045-mregnames Allow symbolic names for registers\n\ 1046-mno-regnames Do not allow symbolic names for registers\n")); 1047#ifdef OBJ_ELF 1048 fprintf (stream, _("\ 1049-mrelocatable support for GCC's -mrelocatble option\n\ 1050-mrelocatable-lib support for GCC's -mrelocatble-lib option\n\ 1051-memb set PPC_EMB bit in ELF flags\n\ 1052-mlittle, -mlittle-endian\n\ 1053 generate code for a little endian machine\n\ 1054-mbig, -mbig-endian generate code for a big endian machine\n\ 1055-msolaris generate code for Solaris\n\ 1056-mno-solaris do not generate code for Solaris\n\ 1057-V print assembler version number\n\ 1058-Qy, -Qn ignored\n")); 1059#endif 1060} 1061 1062/* Set ppc_cpu if it is not already set. */ 1063 1064static void 1065ppc_set_cpu () 1066{ 1067 const char *default_os = TARGET_OS; 1068 const char *default_cpu = TARGET_CPU; 1069 1070 if (ppc_cpu == 0) 1071 { 1072 if (strncmp (default_os, "aix", 3) == 0 1073 && default_os[3] >= '4' && default_os[3] <= '9') 1074 ppc_cpu = PPC_OPCODE_COMMON; 1075 else if (strncmp (default_os, "aix3", 4) == 0) 1076 ppc_cpu = PPC_OPCODE_POWER; 1077 else if (strcmp (default_cpu, "rs6000") == 0) 1078 ppc_cpu = PPC_OPCODE_POWER; 1079 else if (strncmp (default_cpu, "powerpc", 7) == 0) 1080 ppc_cpu = PPC_OPCODE_PPC; 1081 else 1082 as_fatal (_("Unknown default cpu = %s, os = %s"), 1083 default_cpu, default_os); 1084 } 1085} 1086 1087/* Figure out the BFD architecture to use. */ 1088 1089enum bfd_architecture 1090ppc_arch () 1091{ 1092 const char *default_cpu = TARGET_CPU; 1093 ppc_set_cpu (); 1094 1095 if ((ppc_cpu & PPC_OPCODE_PPC) != 0) 1096 return bfd_arch_powerpc; 1097 else if ((ppc_cpu & PPC_OPCODE_POWER) != 0) 1098 return bfd_arch_rs6000; 1099 else if ((ppc_cpu & (PPC_OPCODE_COMMON | PPC_OPCODE_ANY)) != 0) 1100 { 1101 if (strcmp (default_cpu, "rs6000") == 0) 1102 return bfd_arch_rs6000; 1103 else if (strncmp (default_cpu, "powerpc", 7) == 0) 1104 return bfd_arch_powerpc; 1105 } 1106 1107 as_fatal (_("Neither Power nor PowerPC opcodes were selected.")); 1108 return bfd_arch_unknown; 1109} 1110 1111unsigned long 1112ppc_mach () 1113{ 1114 return ppc_size == PPC_OPCODE_64 ? 620 : 0; 1115} 1116 1117#ifdef OBJ_XCOFF 1118int 1119ppc_subseg_align () 1120{ 1121 return ppc_xcoff64 ? 3 : 2; 1122} 1123#endif 1124 1125extern char* 1126ppc_target_format () 1127{ 1128#ifdef OBJ_COFF 1129#ifdef TE_PE 1130 return target_big_endian ? "pe-powerpc" : "pe-powerpcle"; 1131#elif TE_POWERMAC 1132 return "xcoff-powermac"; 1133#else 1134 return ppc_xcoff64 ? "aixcoff64-rs6000" : "aixcoff-rs6000"; 1135#endif 1136#endif 1137#ifdef OBJ_ELF 1138 boolean is64 = BFD_DEFAULT_TARGET_SIZE == 64 && ppc_size == PPC_OPCODE_64; 1139 1140 return (target_big_endian 1141 ? (is64 ? "elf64-powerpc" : "elf32-powerpc") 1142 : (is64 ? "elf64-powerpcle" : "elf32-powerpcle")); 1143#endif 1144} 1145 1146/* This function is called when the assembler starts up. It is called 1147 after the options have been parsed and the output file has been 1148 opened. */ 1149 1150void 1151md_begin () 1152{ 1153 register const struct powerpc_opcode *op; 1154 const struct powerpc_opcode *op_end; 1155 const struct powerpc_macro *macro; 1156 const struct powerpc_macro *macro_end; 1157 boolean dup_insn = false; 1158 1159 ppc_set_cpu (); 1160 1161#ifdef OBJ_ELF 1162 /* Set the ELF flags if desired. */ 1163 if (ppc_flags && !msolaris) 1164 bfd_set_private_flags (stdoutput, ppc_flags); 1165#endif 1166 1167 /* Insert the opcodes into a hash table. */ 1168 ppc_hash = hash_new (); 1169 1170 op_end = powerpc_opcodes + powerpc_num_opcodes; 1171 for (op = powerpc_opcodes; op < op_end; op++) 1172 { 1173 know ((op->opcode & op->mask) == op->opcode); 1174 1175 if ((op->flags & ppc_cpu) != 0 1176 && ((op->flags & (PPC_OPCODE_32 | PPC_OPCODE_64)) == 0 1177 || (op->flags & (PPC_OPCODE_32 | PPC_OPCODE_64)) == ppc_size 1178 || (ppc_cpu & PPC_OPCODE_64_BRIDGE) != 0)) 1179 { 1180 const char *retval; 1181 1182 retval = hash_insert (ppc_hash, op->name, (PTR) op); 1183 if (retval != (const char *) NULL) 1184 { 1185 /* Ignore Power duplicates for -m601. */ 1186 if ((ppc_cpu & PPC_OPCODE_601) != 0 1187 && (op->flags & PPC_OPCODE_POWER) != 0) 1188 continue; 1189 1190 as_bad (_("Internal assembler error for instruction %s"), 1191 op->name); 1192 dup_insn = true; 1193 } 1194 } 1195 } 1196 1197 /* Insert the macros into a hash table. */ 1198 ppc_macro_hash = hash_new (); 1199 1200 macro_end = powerpc_macros + powerpc_num_macros; 1201 for (macro = powerpc_macros; macro < macro_end; macro++) 1202 { 1203 if ((macro->flags & ppc_cpu) != 0) 1204 { 1205 const char *retval; 1206 1207 retval = hash_insert (ppc_macro_hash, macro->name, (PTR) macro); 1208 if (retval != (const char *) NULL) 1209 { 1210 as_bad (_("Internal assembler error for macro %s"), macro->name); 1211 dup_insn = true; 1212 } 1213 } 1214 } 1215 1216 if (dup_insn) 1217 abort (); 1218 1219 /* Tell the main code what the endianness is if it is not overidden 1220 by the user. */ 1221 if (!set_target_endian) 1222 { 1223 set_target_endian = 1; 1224 target_big_endian = PPC_BIG_ENDIAN; 1225 } 1226 1227#ifdef OBJ_XCOFF 1228 ppc_coff_debug_section = coff_section_from_bfd_index (stdoutput, N_DEBUG); 1229 1230 /* Create dummy symbols to serve as initial csects. This forces the 1231 text csects to precede the data csects. These symbols will not 1232 be output. */ 1233 ppc_text_csects = symbol_make ("dummy\001"); 1234 symbol_get_tc (ppc_text_csects)->within = ppc_text_csects; 1235 ppc_data_csects = symbol_make ("dummy\001"); 1236 symbol_get_tc (ppc_data_csects)->within = ppc_data_csects; 1237#endif 1238 1239#ifdef TE_PE 1240 1241 ppc_current_section = text_section; 1242 ppc_previous_section = 0; 1243 1244#endif 1245} 1246 1247/* Insert an operand value into an instruction. */ 1248 1249static unsigned long 1250ppc_insert_operand (insn, operand, val, file, line) 1251 unsigned long insn; 1252 const struct powerpc_operand *operand; 1253 offsetT val; 1254 char *file; 1255 unsigned int line; 1256{ 1257 if (operand->bits != 32) 1258 { 1259 long min, max; 1260 offsetT test; 1261 1262 if ((operand->flags & PPC_OPERAND_SIGNED) != 0) 1263 { 1264 if ((operand->flags & PPC_OPERAND_SIGNOPT) != 0) 1265 max = (1 << operand->bits) - 1; 1266 else 1267 max = (1 << (operand->bits - 1)) - 1; 1268 min = - (1 << (operand->bits - 1)); 1269 1270 if (ppc_size == PPC_OPCODE_32) 1271 { 1272 /* Some people write 32 bit hex constants with the sign 1273 extension done by hand. This shouldn't really be 1274 valid, but, to permit this code to assemble on a 64 1275 bit host, we sign extend the 32 bit value. */ 1276 if (val > 0 1277 && (val & (offsetT) 0x80000000) != 0 1278 && (val & (offsetT) 0xffffffff) == val) 1279 { 1280 val -= 0x80000000; 1281 val -= 0x80000000; 1282 } 1283 } 1284 } 1285 else 1286 { 1287 max = (1 << operand->bits) - 1; 1288 min = 0; 1289 } 1290 1291 if ((operand->flags & PPC_OPERAND_NEGATIVE) != 0) 1292 test = - val; 1293 else 1294 test = val; 1295 1296 if (test < (offsetT) min || test > (offsetT) max) 1297 { 1298 const char *err = 1299 _("operand out of range (%s not between %ld and %ld)"); 1300 char buf[100]; 1301 1302 sprint_value (buf, test); 1303 as_bad_where (file, line, err, buf, min, max); 1304 } 1305 } 1306 1307 if (operand->insert) 1308 { 1309 const char *errmsg; 1310 1311 errmsg = NULL; 1312 insn = (*operand->insert) (insn, (long) val, ppc_cpu | ppc_size, &errmsg); 1313 if (errmsg != (const char *) NULL) 1314 as_bad_where (file, line, errmsg); 1315 } 1316 else 1317 insn |= (((long) val & ((1 << operand->bits) - 1)) 1318 << operand->shift); 1319 1320 return insn; 1321} 1322 1323 1324#ifdef OBJ_ELF 1325/* Parse @got, etc. and return the desired relocation. */ 1326static bfd_reloc_code_real_type 1327ppc_elf_suffix (str_p, exp_p) 1328 char **str_p; 1329 expressionS *exp_p; 1330{ 1331 struct map_bfd { 1332 char *string; 1333 int length; 1334 int reloc; 1335 }; 1336 1337 char ident[20]; 1338 char *str = *str_p; 1339 char *str2; 1340 int ch; 1341 int len; 1342 const struct map_bfd *ptr; 1343 1344#define MAP(str,reloc) { str, sizeof (str)-1, reloc } 1345 1346 static const struct map_bfd mapping[] = { 1347 MAP ("l", (int) BFD_RELOC_LO16), 1348 MAP ("h", (int) BFD_RELOC_HI16), 1349 MAP ("ha", (int) BFD_RELOC_HI16_S), 1350 MAP ("brtaken", (int) BFD_RELOC_PPC_B16_BRTAKEN), 1351 MAP ("brntaken", (int) BFD_RELOC_PPC_B16_BRNTAKEN), 1352 MAP ("got", (int) BFD_RELOC_16_GOTOFF), 1353 MAP ("got@l", (int) BFD_RELOC_LO16_GOTOFF), 1354 MAP ("got@h", (int) BFD_RELOC_HI16_GOTOFF), 1355 MAP ("got@ha", (int) BFD_RELOC_HI16_S_GOTOFF), 1356 MAP ("fixup", (int) BFD_RELOC_CTOR), /* warning with -mrelocatable */ 1357 MAP ("plt", (int) BFD_RELOC_24_PLT_PCREL), 1358 MAP ("pltrel24", (int) BFD_RELOC_24_PLT_PCREL), 1359 MAP ("copy", (int) BFD_RELOC_PPC_COPY), 1360 MAP ("globdat", (int) BFD_RELOC_PPC_GLOB_DAT), 1361 MAP ("local24pc", (int) BFD_RELOC_PPC_LOCAL24PC), 1362 MAP ("local", (int) BFD_RELOC_PPC_LOCAL24PC), 1363 MAP ("pltrel", (int) BFD_RELOC_32_PLT_PCREL), 1364 MAP ("plt@l", (int) BFD_RELOC_LO16_PLTOFF), 1365 MAP ("plt@h", (int) BFD_RELOC_HI16_PLTOFF), 1366 MAP ("plt@ha", (int) BFD_RELOC_HI16_S_PLTOFF), 1367 MAP ("sdarel", (int) BFD_RELOC_GPREL16), 1368 MAP ("sectoff", (int) BFD_RELOC_32_BASEREL), 1369 MAP ("sectoff@l", (int) BFD_RELOC_LO16_BASEREL), 1370 MAP ("sectoff@h", (int) BFD_RELOC_HI16_BASEREL), 1371 MAP ("sectoff@ha", (int) BFD_RELOC_HI16_S_BASEREL), 1372 MAP ("naddr", (int) BFD_RELOC_PPC_EMB_NADDR32), 1373 MAP ("naddr16", (int) BFD_RELOC_PPC_EMB_NADDR16), 1374 MAP ("naddr@l", (int) BFD_RELOC_PPC_EMB_NADDR16_LO), 1375 MAP ("naddr@h", (int) BFD_RELOC_PPC_EMB_NADDR16_HI), 1376 MAP ("naddr@ha", (int) BFD_RELOC_PPC_EMB_NADDR16_HA), 1377 MAP ("sdai16", (int) BFD_RELOC_PPC_EMB_SDAI16), 1378 MAP ("sda2rel", (int) BFD_RELOC_PPC_EMB_SDA2REL), 1379 MAP ("sda2i16", (int) BFD_RELOC_PPC_EMB_SDA2I16), 1380 MAP ("sda21", (int) BFD_RELOC_PPC_EMB_SDA21), 1381 MAP ("mrkref", (int) BFD_RELOC_PPC_EMB_MRKREF), 1382 MAP ("relsect", (int) BFD_RELOC_PPC_EMB_RELSEC16), 1383 MAP ("relsect@l", (int) BFD_RELOC_PPC_EMB_RELST_LO), 1384 MAP ("relsect@h", (int) BFD_RELOC_PPC_EMB_RELST_HI), 1385 MAP ("relsect@ha", (int) BFD_RELOC_PPC_EMB_RELST_HA), 1386 MAP ("bitfld", (int) BFD_RELOC_PPC_EMB_BIT_FLD), 1387 MAP ("relsda", (int) BFD_RELOC_PPC_EMB_RELSDA), 1388 MAP ("xgot", (int) BFD_RELOC_PPC_TOC16), 1389#if BFD_DEFAULT_TARGET_SIZE == 64 1390 MAP ("higher", - (int) BFD_RELOC_PPC64_HIGHER), 1391 MAP ("highera", - (int) BFD_RELOC_PPC64_HIGHER_S), 1392 MAP ("highest", - (int) BFD_RELOC_PPC64_HIGHEST), 1393 MAP ("highesta", - (int) BFD_RELOC_PPC64_HIGHEST_S), 1394 MAP ("tocbase", - (int) BFD_RELOC_PPC64_TOC), 1395 MAP ("toc", - (int) BFD_RELOC_PPC_TOC16), 1396 MAP ("toc@l", - (int) BFD_RELOC_PPC64_TOC16_LO), 1397 MAP ("toc@h", - (int) BFD_RELOC_PPC64_TOC16_HI), 1398 MAP ("toc@ha", - (int) BFD_RELOC_PPC64_TOC16_HA), 1399#endif 1400 { (char *) 0, 0, (int) BFD_RELOC_UNUSED } 1401 }; 1402 1403 if (*str++ != '@') 1404 return BFD_RELOC_UNUSED; 1405 1406 for (ch = *str, str2 = ident; 1407 (str2 < ident + sizeof (ident) - 1 1408 && (ISALNUM (ch) || ch == '@')); 1409 ch = *++str) 1410 { 1411 *str2++ = TOLOWER (ch); 1412 } 1413 1414 *str2 = '\0'; 1415 len = str2 - ident; 1416 1417 ch = ident[0]; 1418 for (ptr = &mapping[0]; ptr->length > 0; ptr++) 1419 if (ch == ptr->string[0] 1420 && len == ptr->length 1421 && memcmp (ident, ptr->string, ptr->length) == 0) 1422 { 1423 int reloc = ptr->reloc; 1424 1425 if (BFD_DEFAULT_TARGET_SIZE == 64 && reloc < 0) 1426 { 1427 if (ppc_size != PPC_OPCODE_64) 1428 return BFD_RELOC_UNUSED; 1429 reloc = -reloc; 1430 } 1431 1432 if (exp_p->X_add_number != 0 1433 && (reloc == (int) BFD_RELOC_16_GOTOFF 1434 || reloc == (int) BFD_RELOC_LO16_GOTOFF 1435 || reloc == (int) BFD_RELOC_HI16_GOTOFF 1436 || reloc == (int) BFD_RELOC_HI16_S_GOTOFF)) 1437 as_warn (_("identifier+constant@got means identifier@got+constant")); 1438 1439 /* Now check for identifier@suffix+constant. */ 1440 if (*str == '-' || *str == '+') 1441 { 1442 char *orig_line = input_line_pointer; 1443 expressionS new_exp; 1444 1445 input_line_pointer = str; 1446 expression (&new_exp); 1447 if (new_exp.X_op == O_constant) 1448 { 1449 exp_p->X_add_number += new_exp.X_add_number; 1450 str = input_line_pointer; 1451 } 1452 1453 if (&input_line_pointer != str_p) 1454 input_line_pointer = orig_line; 1455 } 1456 *str_p = str; 1457 1458 if (BFD_DEFAULT_TARGET_SIZE == 64 1459 && reloc == (int) BFD_RELOC_PPC64_TOC 1460 && exp_p->X_op == O_symbol) 1461 { 1462 /* This reloc type ignores the symbol. Change the symbol 1463 so that the dummy .TOC. symbol can be omitted from the 1464 object file. */ 1465 exp_p->X_add_symbol = &abs_symbol; 1466 } 1467 1468 return (bfd_reloc_code_real_type) reloc; 1469 } 1470 1471 return BFD_RELOC_UNUSED; 1472} 1473 1474/* Like normal .long/.short/.word, except support @got, etc. 1475 Clobbers input_line_pointer, checks end-of-line. */ 1476static void 1477ppc_elf_cons (nbytes) 1478 register int nbytes; /* 1=.byte, 2=.word, 4=.long, 8=.llong. */ 1479{ 1480 expressionS exp; 1481 bfd_reloc_code_real_type reloc; 1482 1483 if (is_it_end_of_statement ()) 1484 { 1485 demand_empty_rest_of_line (); 1486 return; 1487 } 1488 1489 do 1490 { 1491 expression (&exp); 1492 if (exp.X_op == O_symbol 1493 && *input_line_pointer == '@' 1494 && (reloc = ppc_elf_suffix (&input_line_pointer, 1495 &exp)) != BFD_RELOC_UNUSED) 1496 { 1497 reloc_howto_type *reloc_howto; 1498 int size; 1499 1500 reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc); 1501 size = bfd_get_reloc_size (reloc_howto); 1502 1503 if (size > nbytes) 1504 { 1505 as_bad (_("%s relocations do not fit in %d bytes\n"), 1506 reloc_howto->name, nbytes); 1507 } 1508 else 1509 { 1510 char *p; 1511 int offset; 1512 1513 p = frag_more (nbytes); 1514 offset = 0; 1515 if (target_big_endian) 1516 offset = nbytes - size; 1517 fix_new_exp (frag_now, p - frag_now->fr_literal + offset, size, 1518 &exp, 0, reloc); 1519 } 1520 } 1521 else 1522 emit_expr (&exp, (unsigned int) nbytes); 1523 } 1524 while (*input_line_pointer++ == ','); 1525 1526 /* Put terminator back into stream. */ 1527 input_line_pointer--; 1528 demand_empty_rest_of_line (); 1529} 1530 1531/* Solaris pseduo op to change to the .rodata section. */ 1532static void 1533ppc_elf_rdata (xxx) 1534 int xxx; 1535{ 1536 char *save_line = input_line_pointer; 1537 static char section[] = ".rodata\n"; 1538 1539 /* Just pretend this is .section .rodata */ 1540 input_line_pointer = section; 1541 obj_elf_section (xxx); 1542 1543 input_line_pointer = save_line; 1544} 1545 1546/* Pseudo op to make file scope bss items. */ 1547static void 1548ppc_elf_lcomm (xxx) 1549 int xxx ATTRIBUTE_UNUSED; 1550{ 1551 register char *name; 1552 register char c; 1553 register char *p; 1554 offsetT size; 1555 register symbolS *symbolP; 1556 offsetT align; 1557 segT old_sec; 1558 int old_subsec; 1559 char *pfrag; 1560 int align2; 1561 1562 name = input_line_pointer; 1563 c = get_symbol_end (); 1564 1565 /* just after name is now '\0'. */ 1566 p = input_line_pointer; 1567 *p = c; 1568 SKIP_WHITESPACE (); 1569 if (*input_line_pointer != ',') 1570 { 1571 as_bad (_("Expected comma after symbol-name: rest of line ignored.")); 1572 ignore_rest_of_line (); 1573 return; 1574 } 1575 1576 input_line_pointer++; /* skip ',' */ 1577 if ((size = get_absolute_expression ()) < 0) 1578 { 1579 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) size); 1580 ignore_rest_of_line (); 1581 return; 1582 } 1583 1584 /* The third argument to .lcomm is the alignment. */ 1585 if (*input_line_pointer != ',') 1586 align = 8; 1587 else 1588 { 1589 ++input_line_pointer; 1590 align = get_absolute_expression (); 1591 if (align <= 0) 1592 { 1593 as_warn (_("ignoring bad alignment")); 1594 align = 8; 1595 } 1596 } 1597 1598 *p = 0; 1599 symbolP = symbol_find_or_make (name); 1600 *p = c; 1601 1602 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP)) 1603 { 1604 as_bad (_("Ignoring attempt to re-define symbol `%s'."), 1605 S_GET_NAME (symbolP)); 1606 ignore_rest_of_line (); 1607 return; 1608 } 1609 1610 if (S_GET_VALUE (symbolP) && S_GET_VALUE (symbolP) != (valueT) size) 1611 { 1612 as_bad (_("Length of .lcomm \"%s\" is already %ld. Not changed to %ld."), 1613 S_GET_NAME (symbolP), 1614 (long) S_GET_VALUE (symbolP), 1615 (long) size); 1616 1617 ignore_rest_of_line (); 1618 return; 1619 } 1620 1621 /* Allocate_bss. */ 1622 old_sec = now_seg; 1623 old_subsec = now_subseg; 1624 if (align) 1625 { 1626 /* Convert to a power of 2 alignment. */ 1627 for (align2 = 0; (align & 1) == 0; align >>= 1, ++align2); 1628 if (align != 1) 1629 { 1630 as_bad (_("Common alignment not a power of 2")); 1631 ignore_rest_of_line (); 1632 return; 1633 } 1634 } 1635 else 1636 align2 = 0; 1637 1638 record_alignment (bss_section, align2); 1639 subseg_set (bss_section, 0); 1640 if (align2) 1641 frag_align (align2, 0, 0); 1642 if (S_GET_SEGMENT (symbolP) == bss_section) 1643 symbol_get_frag (symbolP)->fr_symbol = 0; 1644 symbol_set_frag (symbolP, frag_now); 1645 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP, size, 1646 (char *) 0); 1647 *pfrag = 0; 1648 S_SET_SIZE (symbolP, size); 1649 S_SET_SEGMENT (symbolP, bss_section); 1650 subseg_set (old_sec, old_subsec); 1651 demand_empty_rest_of_line (); 1652} 1653 1654/* Validate any relocations emitted for -mrelocatable, possibly adding 1655 fixups for word relocations in writable segments, so we can adjust 1656 them at runtime. */ 1657static void 1658ppc_elf_validate_fix (fixp, seg) 1659 fixS *fixp; 1660 segT seg; 1661{ 1662 if (fixp->fx_done || fixp->fx_pcrel) 1663 return; 1664 1665 switch (shlib) 1666 { 1667 case SHLIB_NONE: 1668 case SHLIB_PIC: 1669 return; 1670 1671 case SHLIB_MRELOCATABLE: 1672 if (fixp->fx_r_type <= BFD_RELOC_UNUSED 1673 && fixp->fx_r_type != BFD_RELOC_16_GOTOFF 1674 && fixp->fx_r_type != BFD_RELOC_HI16_GOTOFF 1675 && fixp->fx_r_type != BFD_RELOC_LO16_GOTOFF 1676 && fixp->fx_r_type != BFD_RELOC_HI16_S_GOTOFF 1677 && fixp->fx_r_type != BFD_RELOC_32_BASEREL 1678 && fixp->fx_r_type != BFD_RELOC_LO16_BASEREL 1679 && fixp->fx_r_type != BFD_RELOC_HI16_BASEREL 1680 && fixp->fx_r_type != BFD_RELOC_HI16_S_BASEREL 1681 && (seg->flags & SEC_LOAD) != 0 1682 && strcmp (segment_name (seg), ".got2") != 0 1683 && strcmp (segment_name (seg), ".dtors") != 0 1684 && strcmp (segment_name (seg), ".ctors") != 0 1685 && strcmp (segment_name (seg), ".fixup") != 0 1686 && strcmp (segment_name (seg), ".gcc_except_table") != 0 1687 && strcmp (segment_name (seg), ".eh_frame") != 0 1688 && strcmp (segment_name (seg), ".ex_shared") != 0) 1689 { 1690 if ((seg->flags & (SEC_READONLY | SEC_CODE)) != 0 1691 || fixp->fx_r_type != BFD_RELOC_CTOR) 1692 { 1693 as_bad_where (fixp->fx_file, fixp->fx_line, 1694 _("Relocation cannot be done when using -mrelocatable")); 1695 } 1696 } 1697 return; 1698 } 1699} 1700 1701#if BFD_DEFAULT_TARGET_SIZE == 64 1702/* Don't emit .TOC. symbol. */ 1703int 1704ppc_elf_frob_symbol (sym) 1705 symbolS *sym; 1706{ 1707 const char *name; 1708 1709 name = S_GET_NAME (sym); 1710 if (name != NULL && strcmp (name, ".TOC.") == 0) 1711 { 1712 S_CLEAR_EXTERNAL (sym); 1713 return 1; 1714 } 1715 1716 return 0; 1717} 1718#endif 1719#endif /* OBJ_ELF */ 1720 1721#ifdef TE_PE 1722 1723/* 1724 * Summary of parse_toc_entry. 1725 * 1726 * in: Input_line_pointer points to the '[' in one of: 1727 * 1728 * [toc] [tocv] [toc32] [toc64] 1729 * 1730 * Anything else is an error of one kind or another. 1731 * 1732 * out: 1733 * return value: success or failure 1734 * toc_kind: kind of toc reference 1735 * input_line_pointer: 1736 * success: first char after the ']' 1737 * failure: unchanged 1738 * 1739 * settings: 1740 * 1741 * [toc] - rv == success, toc_kind = default_toc 1742 * [tocv] - rv == success, toc_kind = data_in_toc 1743 * [toc32] - rv == success, toc_kind = must_be_32 1744 * [toc64] - rv == success, toc_kind = must_be_64 1745 * 1746 */ 1747 1748enum toc_size_qualifier 1749{ 1750 default_toc, /* The toc cell constructed should be the system default size */ 1751 data_in_toc, /* This is a direct reference to a toc cell */ 1752 must_be_32, /* The toc cell constructed must be 32 bits wide */ 1753 must_be_64 /* The toc cell constructed must be 64 bits wide */ 1754}; 1755 1756static int 1757parse_toc_entry (toc_kind) 1758 enum toc_size_qualifier *toc_kind; 1759{ 1760 char *start; 1761 char *toc_spec; 1762 char c; 1763 enum toc_size_qualifier t; 1764 1765 /* Save the input_line_pointer. */ 1766 start = input_line_pointer; 1767 1768 /* Skip over the '[' , and whitespace. */ 1769 ++input_line_pointer; 1770 SKIP_WHITESPACE (); 1771 1772 /* Find the spelling of the operand. */ 1773 toc_spec = input_line_pointer; 1774 c = get_symbol_end (); 1775 1776 if (strcmp (toc_spec, "toc") == 0) 1777 { 1778 t = default_toc; 1779 } 1780 else if (strcmp (toc_spec, "tocv") == 0) 1781 { 1782 t = data_in_toc; 1783 } 1784 else if (strcmp (toc_spec, "toc32") == 0) 1785 { 1786 t = must_be_32; 1787 } 1788 else if (strcmp (toc_spec, "toc64") == 0) 1789 { 1790 t = must_be_64; 1791 } 1792 else 1793 { 1794 as_bad (_("syntax error: invalid toc specifier `%s'"), toc_spec); 1795 *input_line_pointer = c; 1796 input_line_pointer = start; 1797 return 0; 1798 } 1799 1800 /* Now find the ']'. */ 1801 *input_line_pointer = c; 1802 1803 SKIP_WHITESPACE (); /* leading whitespace could be there. */ 1804 c = *input_line_pointer++; /* input_line_pointer->past char in c. */ 1805 1806 if (c != ']') 1807 { 1808 as_bad (_("syntax error: expected `]', found `%c'"), c); 1809 input_line_pointer = start; 1810 return 0; 1811 } 1812 1813 *toc_kind = t; 1814 return 1; 1815} 1816#endif 1817 1818 1819/* We need to keep a list of fixups. We can't simply generate them as 1820 we go, because that would require us to first create the frag, and 1821 that would screw up references to ``.''. */ 1822 1823struct ppc_fixup 1824{ 1825 expressionS exp; 1826 int opindex; 1827 bfd_reloc_code_real_type reloc; 1828}; 1829 1830#define MAX_INSN_FIXUPS (5) 1831 1832/* This routine is called for each instruction to be assembled. */ 1833 1834void 1835md_assemble (str) 1836 char *str; 1837{ 1838 char *s; 1839 const struct powerpc_opcode *opcode; 1840 unsigned long insn; 1841 const unsigned char *opindex_ptr; 1842 int skip_optional; 1843 int need_paren; 1844 int next_opindex; 1845 struct ppc_fixup fixups[MAX_INSN_FIXUPS]; 1846 int fc; 1847 char *f; 1848 int i; 1849#ifdef OBJ_ELF 1850 bfd_reloc_code_real_type reloc; 1851#endif 1852 1853 /* Get the opcode. */ 1854 for (s = str; *s != '\0' && ! ISSPACE (*s); s++) 1855 ; 1856 if (*s != '\0') 1857 *s++ = '\0'; 1858 1859 /* Look up the opcode in the hash table. */ 1860 opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, str); 1861 if (opcode == (const struct powerpc_opcode *) NULL) 1862 { 1863 const struct powerpc_macro *macro; 1864 1865 macro = (const struct powerpc_macro *) hash_find (ppc_macro_hash, str); 1866 if (macro == (const struct powerpc_macro *) NULL) 1867 as_bad (_("Unrecognized opcode: `%s'"), str); 1868 else 1869 ppc_macro (s, macro); 1870 1871 return; 1872 } 1873 1874 insn = opcode->opcode; 1875 1876 str = s; 1877 while (ISSPACE (*str)) 1878 ++str; 1879 1880 /* PowerPC operands are just expressions. The only real issue is 1881 that a few operand types are optional. All cases which might use 1882 an optional operand separate the operands only with commas (in 1883 some cases parentheses are used, as in ``lwz 1,0(1)'' but such 1884 cases never have optional operands). There is never more than 1885 one optional operand for an instruction. So, before we start 1886 seriously parsing the operands, we check to see if we have an 1887 optional operand, and, if we do, we count the number of commas to 1888 see whether the operand should be omitted. */ 1889 skip_optional = 0; 1890 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++) 1891 { 1892 const struct powerpc_operand *operand; 1893 1894 operand = &powerpc_operands[*opindex_ptr]; 1895 if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0) 1896 { 1897 unsigned int opcount; 1898 1899 /* There is an optional operand. Count the number of 1900 commas in the input line. */ 1901 if (*str == '\0') 1902 opcount = 0; 1903 else 1904 { 1905 opcount = 1; 1906 s = str; 1907 while ((s = strchr (s, ',')) != (char *) NULL) 1908 { 1909 ++opcount; 1910 ++s; 1911 } 1912 } 1913 1914 /* If there are fewer operands in the line then are called 1915 for by the instruction, we want to skip the optional 1916 operand. */ 1917 if (opcount < strlen (opcode->operands)) 1918 skip_optional = 1; 1919 1920 break; 1921 } 1922 } 1923 1924 /* Gather the operands. */ 1925 need_paren = 0; 1926 next_opindex = 0; 1927 fc = 0; 1928 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++) 1929 { 1930 const struct powerpc_operand *operand; 1931 const char *errmsg; 1932 char *hold; 1933 expressionS ex; 1934 char endc; 1935 1936 if (next_opindex == 0) 1937 operand = &powerpc_operands[*opindex_ptr]; 1938 else 1939 { 1940 operand = &powerpc_operands[next_opindex]; 1941 next_opindex = 0; 1942 } 1943 1944 errmsg = NULL; 1945 1946 /* If this is a fake operand, then we do not expect anything 1947 from the input. */ 1948 if ((operand->flags & PPC_OPERAND_FAKE) != 0) 1949 { 1950 insn = (*operand->insert) (insn, 0L, ppc_cpu | ppc_size, &errmsg); 1951 if (errmsg != (const char *) NULL) 1952 as_bad (errmsg); 1953 continue; 1954 } 1955 1956 /* If this is an optional operand, and we are skipping it, just 1957 insert a zero. */ 1958 if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0 1959 && skip_optional) 1960 { 1961 if (operand->insert) 1962 { 1963 insn = (*operand->insert) (insn, 0L, ppc_cpu | ppc_size, &errmsg); 1964 if (errmsg != (const char *) NULL) 1965 as_bad (errmsg); 1966 } 1967 if ((operand->flags & PPC_OPERAND_NEXT) != 0) 1968 next_opindex = *opindex_ptr + 1; 1969 continue; 1970 } 1971 1972 /* Gather the operand. */ 1973 hold = input_line_pointer; 1974 input_line_pointer = str; 1975 1976#ifdef TE_PE 1977 if (*input_line_pointer == '[') 1978 { 1979 /* We are expecting something like the second argument here: 1980 * 1981 * lwz r4,[toc].GS.0.static_int(rtoc) 1982 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1983 * The argument following the `]' must be a symbol name, and the 1984 * register must be the toc register: 'rtoc' or '2' 1985 * 1986 * The effect is to 0 as the displacement field 1987 * in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or 1988 * the appropriate variation) reloc against it based on the symbol. 1989 * The linker will build the toc, and insert the resolved toc offset. 1990 * 1991 * Note: 1992 * o The size of the toc entry is currently assumed to be 1993 * 32 bits. This should not be assumed to be a hard coded 1994 * number. 1995 * o In an effort to cope with a change from 32 to 64 bits, 1996 * there are also toc entries that are specified to be 1997 * either 32 or 64 bits: 1998 * lwz r4,[toc32].GS.0.static_int(rtoc) 1999 * lwz r4,[toc64].GS.0.static_int(rtoc) 2000 * These demand toc entries of the specified size, and the 2001 * instruction probably requires it. 2002 */ 2003 2004 int valid_toc; 2005 enum toc_size_qualifier toc_kind; 2006 bfd_reloc_code_real_type toc_reloc; 2007 2008 /* Go parse off the [tocXX] part. */ 2009 valid_toc = parse_toc_entry (&toc_kind); 2010 2011 if (!valid_toc) 2012 { 2013 /* Note: message has already been issued. 2014 FIXME: what sort of recovery should we do? 2015 demand_rest_of_line (); return; ? */ 2016 } 2017 2018 /* Now get the symbol following the ']'. */ 2019 expression (&ex); 2020 2021 switch (toc_kind) 2022 { 2023 case default_toc: 2024 /* In this case, we may not have seen the symbol yet, 2025 since it is allowed to appear on a .extern or .globl 2026 or just be a label in the .data section. */ 2027 toc_reloc = BFD_RELOC_PPC_TOC16; 2028 break; 2029 case data_in_toc: 2030 /* 1. The symbol must be defined and either in the toc 2031 section, or a global. 2032 2. The reloc generated must have the TOCDEFN flag set 2033 in upper bit mess of the reloc type. 2034 FIXME: It's a little confusing what the tocv 2035 qualifier can be used for. At the very least, I've 2036 seen three uses, only one of which I'm sure I can 2037 explain. */ 2038 if (ex.X_op == O_symbol) 2039 { 2040 assert (ex.X_add_symbol != NULL); 2041 if (symbol_get_bfdsym (ex.X_add_symbol)->section 2042 != tocdata_section) 2043 { 2044 as_bad (_("[tocv] symbol is not a toc symbol")); 2045 } 2046 } 2047 2048 toc_reloc = BFD_RELOC_PPC_TOC16; 2049 break; 2050 case must_be_32: 2051 /* FIXME: these next two specifically specify 32/64 bit 2052 toc entries. We don't support them today. Is this 2053 the right way to say that? */ 2054 toc_reloc = BFD_RELOC_UNUSED; 2055 as_bad (_("Unimplemented toc32 expression modifier")); 2056 break; 2057 case must_be_64: 2058 /* FIXME: see above. */ 2059 toc_reloc = BFD_RELOC_UNUSED; 2060 as_bad (_("Unimplemented toc64 expression modifier")); 2061 break; 2062 default: 2063 fprintf (stderr, 2064 _("Unexpected return value [%d] from parse_toc_entry!\n"), 2065 toc_kind); 2066 abort (); 2067 break; 2068 } 2069 2070 /* We need to generate a fixup for this expression. */ 2071 if (fc >= MAX_INSN_FIXUPS) 2072 as_fatal (_("too many fixups")); 2073 2074 fixups[fc].reloc = toc_reloc; 2075 fixups[fc].exp = ex; 2076 fixups[fc].opindex = *opindex_ptr; 2077 ++fc; 2078 2079 /* Ok. We've set up the fixup for the instruction. Now make it 2080 look like the constant 0 was found here. */ 2081 ex.X_unsigned = 1; 2082 ex.X_op = O_constant; 2083 ex.X_add_number = 0; 2084 ex.X_add_symbol = NULL; 2085 ex.X_op_symbol = NULL; 2086 } 2087 2088 else 2089#endif /* TE_PE */ 2090 { 2091 if (! register_name (&ex)) 2092 { 2093 if ((operand->flags & PPC_OPERAND_CR) != 0) 2094 cr_operand = true; 2095 expression (&ex); 2096 cr_operand = false; 2097 } 2098 } 2099 2100 str = input_line_pointer; 2101 input_line_pointer = hold; 2102 2103 if (ex.X_op == O_illegal) 2104 as_bad (_("illegal operand")); 2105 else if (ex.X_op == O_absent) 2106 as_bad (_("missing operand")); 2107 else if (ex.X_op == O_register) 2108 { 2109 insn = ppc_insert_operand (insn, operand, ex.X_add_number, 2110 (char *) NULL, 0); 2111 } 2112 else if (ex.X_op == O_constant) 2113 { 2114#ifdef OBJ_ELF 2115 /* Allow @HA, @L, @H on constants. */ 2116 char *orig_str = str; 2117 2118 if ((reloc = ppc_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED) 2119 switch (reloc) 2120 { 2121 default: 2122 str = orig_str; 2123 break; 2124 2125 case BFD_RELOC_LO16: 2126 /* X_unsigned is the default, so if the user has done 2127 something which cleared it, we always produce a 2128 signed value. */ 2129 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED)) 2130 ex.X_add_number &= 0xffff; 2131 else 2132 ex.X_add_number = SEX16 (ex.X_add_number); 2133 break; 2134 2135 case BFD_RELOC_HI16: 2136 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED)) 2137 ex.X_add_number = PPC_HI (ex.X_add_number); 2138 else 2139 ex.X_add_number = SEX16 (PPC_HI (ex.X_add_number)); 2140 break; 2141 2142 case BFD_RELOC_HI16_S: 2143 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED)) 2144 ex.X_add_number = PPC_HA (ex.X_add_number); 2145 else 2146 ex.X_add_number = SEX16 (PPC_HA (ex.X_add_number)); 2147 break; 2148 2149#if BFD_DEFAULT_TARGET_SIZE == 64 2150 case BFD_RELOC_PPC64_HIGHER: 2151 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED)) 2152 ex.X_add_number = PPC_HIGHER (ex.X_add_number); 2153 else 2154 ex.X_add_number = SEX16 (PPC_HIGHER (ex.X_add_number)); 2155 break; 2156 2157 case BFD_RELOC_PPC64_HIGHER_S: 2158 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED)) 2159 ex.X_add_number = PPC_HIGHERA (ex.X_add_number); 2160 else 2161 ex.X_add_number = SEX16 (PPC_HIGHERA (ex.X_add_number)); 2162 break; 2163 2164 case BFD_RELOC_PPC64_HIGHEST: 2165 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED)) 2166 ex.X_add_number = PPC_HIGHEST (ex.X_add_number); 2167 else 2168 ex.X_add_number = SEX16 (PPC_HIGHEST (ex.X_add_number)); 2169 break; 2170 2171 case BFD_RELOC_PPC64_HIGHEST_S: 2172 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED)) 2173 ex.X_add_number = PPC_HIGHESTA (ex.X_add_number); 2174 else 2175 ex.X_add_number = SEX16 (PPC_HIGHESTA (ex.X_add_number)); 2176 break; 2177#endif /* BFD_DEFAULT_TARGET_SIZE == 64 */ 2178 } 2179#endif /* OBJ_ELF */ 2180 insn = ppc_insert_operand (insn, operand, ex.X_add_number, 2181 (char *) NULL, 0); 2182 } 2183#ifdef OBJ_ELF 2184 else if ((reloc = ppc_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED) 2185 { 2186 /* For the absolute forms of branches, convert the PC 2187 relative form back into the absolute. */ 2188 if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0) 2189 { 2190 switch (reloc) 2191 { 2192 case BFD_RELOC_PPC_B26: 2193 reloc = BFD_RELOC_PPC_BA26; 2194 break; 2195 case BFD_RELOC_PPC_B16: 2196 reloc = BFD_RELOC_PPC_BA16; 2197 break; 2198 case BFD_RELOC_PPC_B16_BRTAKEN: 2199 reloc = BFD_RELOC_PPC_BA16_BRTAKEN; 2200 break; 2201 case BFD_RELOC_PPC_B16_BRNTAKEN: 2202 reloc = BFD_RELOC_PPC_BA16_BRNTAKEN; 2203 break; 2204 default: 2205 break; 2206 } 2207 } 2208 2209 if (BFD_DEFAULT_TARGET_SIZE == 64 2210 && ppc_size == PPC_OPCODE_64 2211 && (operand->flags & PPC_OPERAND_DS) != 0) 2212 { 2213 switch (reloc) 2214 { 2215 case BFD_RELOC_16: 2216 reloc = BFD_RELOC_PPC64_ADDR16_DS; 2217 break; 2218 case BFD_RELOC_LO16: 2219 reloc = BFD_RELOC_PPC64_ADDR16_LO_DS; 2220 break; 2221 case BFD_RELOC_16_GOTOFF: 2222 reloc = BFD_RELOC_PPC64_GOT16_DS; 2223 break; 2224 case BFD_RELOC_LO16_GOTOFF: 2225 reloc = BFD_RELOC_PPC64_GOT16_LO_DS; 2226 break; 2227 case BFD_RELOC_LO16_PLTOFF: 2228 reloc = BFD_RELOC_PPC64_PLT16_LO_DS; 2229 break; 2230 case BFD_RELOC_32_BASEREL: 2231 reloc = BFD_RELOC_PPC64_SECTOFF_DS; 2232 break; 2233 case BFD_RELOC_LO16_BASEREL: 2234 reloc = BFD_RELOC_PPC64_SECTOFF_LO_DS; 2235 break; 2236 case BFD_RELOC_PPC_TOC16: 2237 reloc = BFD_RELOC_PPC64_TOC16_DS; 2238 break; 2239 case BFD_RELOC_PPC64_TOC16_LO: 2240 reloc = BFD_RELOC_PPC64_TOC16_LO_DS; 2241 break; 2242 case BFD_RELOC_PPC64_PLTGOT16: 2243 reloc = BFD_RELOC_PPC64_PLTGOT16_DS; 2244 break; 2245 case BFD_RELOC_PPC64_PLTGOT16_LO: 2246 reloc = BFD_RELOC_PPC64_PLTGOT16_LO_DS; 2247 break; 2248 default: 2249 as_bad (_("unsupported relocation for DS offset field")); 2250 break; 2251 } 2252 } 2253 2254 /* We need to generate a fixup for this expression. */ 2255 if (fc >= MAX_INSN_FIXUPS) 2256 as_fatal (_("too many fixups")); 2257 fixups[fc].exp = ex; 2258 fixups[fc].opindex = 0; 2259 fixups[fc].reloc = reloc; 2260 ++fc; 2261 } 2262#endif /* OBJ_ELF */ 2263 2264 else 2265 { 2266 /* We need to generate a fixup for this expression. */ 2267 if (fc >= MAX_INSN_FIXUPS) 2268 as_fatal (_("too many fixups")); 2269 fixups[fc].exp = ex; 2270 fixups[fc].opindex = *opindex_ptr; 2271 fixups[fc].reloc = BFD_RELOC_UNUSED; 2272 ++fc; 2273 } 2274 2275 if (need_paren) 2276 { 2277 endc = ')'; 2278 need_paren = 0; 2279 } 2280 else if ((operand->flags & PPC_OPERAND_PARENS) != 0) 2281 { 2282 endc = '('; 2283 need_paren = 1; 2284 } 2285 else 2286 endc = ','; 2287 2288 /* The call to expression should have advanced str past any 2289 whitespace. */ 2290 if (*str != endc 2291 && (endc != ',' || *str != '\0')) 2292 { 2293 as_bad (_("syntax error; found `%c' but expected `%c'"), *str, endc); 2294 break; 2295 } 2296 2297 if (*str != '\0') 2298 ++str; 2299 } 2300 2301 while (ISSPACE (*str)) 2302 ++str; 2303 2304 if (*str != '\0') 2305 as_bad (_("junk at end of line: `%s'"), str); 2306 2307 /* Write out the instruction. */ 2308 f = frag_more (4); 2309 md_number_to_chars (f, insn, 4); 2310 2311#ifdef OBJ_ELF 2312 dwarf2_emit_insn (4); 2313#endif 2314 2315 /* Create any fixups. At this point we do not use a 2316 bfd_reloc_code_real_type, but instead just use the 2317 BFD_RELOC_UNUSED plus the operand index. This lets us easily 2318 handle fixups for any operand type, although that is admittedly 2319 not a very exciting feature. We pick a BFD reloc type in 2320 md_apply_fix3. */ 2321 for (i = 0; i < fc; i++) 2322 { 2323 const struct powerpc_operand *operand; 2324 2325 operand = &powerpc_operands[fixups[i].opindex]; 2326 if (fixups[i].reloc != BFD_RELOC_UNUSED) 2327 { 2328 reloc_howto_type *reloc_howto; 2329 int size; 2330 int offset; 2331 fixS *fixP; 2332 2333 reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc); 2334 if (!reloc_howto) 2335 abort (); 2336 2337 size = bfd_get_reloc_size (reloc_howto); 2338 offset = target_big_endian ? (4 - size) : 0; 2339 2340 if (size < 1 || size > 4) 2341 abort (); 2342 2343 fixP = fix_new_exp (frag_now, 2344 f - frag_now->fr_literal + offset, 2345 size, 2346 &fixups[i].exp, 2347 reloc_howto->pc_relative, 2348 fixups[i].reloc); 2349 2350 /* Turn off complaints that the addend is too large for things like 2351 foo+100000@ha. */ 2352 switch (fixups[i].reloc) 2353 { 2354 case BFD_RELOC_16_GOTOFF: 2355 case BFD_RELOC_PPC_TOC16: 2356 case BFD_RELOC_LO16: 2357 case BFD_RELOC_HI16: 2358 case BFD_RELOC_HI16_S: 2359#ifdef OBJ_ELF 2360#if BFD_DEFAULT_TARGET_SIZE == 64 2361 case BFD_RELOC_PPC64_HIGHER: 2362 case BFD_RELOC_PPC64_HIGHER_S: 2363 case BFD_RELOC_PPC64_HIGHEST: 2364 case BFD_RELOC_PPC64_HIGHEST_S: 2365#endif 2366#endif 2367 fixP->fx_no_overflow = 1; 2368 break; 2369 default: 2370 break; 2371 } 2372 } 2373 else 2374 fix_new_exp (frag_now, 2375 f - frag_now->fr_literal, 2376 4, 2377 &fixups[i].exp, 2378 (operand->flags & PPC_OPERAND_RELATIVE) != 0, 2379 ((bfd_reloc_code_real_type) 2380 (fixups[i].opindex + (int) BFD_RELOC_UNUSED))); 2381 } 2382} 2383 2384/* Handle a macro. Gather all the operands, transform them as 2385 described by the macro, and call md_assemble recursively. All the 2386 operands are separated by commas; we don't accept parentheses 2387 around operands here. */ 2388 2389static void 2390ppc_macro (str, macro) 2391 char *str; 2392 const struct powerpc_macro *macro; 2393{ 2394 char *operands[10]; 2395 unsigned int count; 2396 char *s; 2397 unsigned int len; 2398 const char *format; 2399 int arg; 2400 char *send; 2401 char *complete; 2402 2403 /* Gather the users operands into the operands array. */ 2404 count = 0; 2405 s = str; 2406 while (1) 2407 { 2408 if (count >= sizeof operands / sizeof operands[0]) 2409 break; 2410 operands[count++] = s; 2411 s = strchr (s, ','); 2412 if (s == (char *) NULL) 2413 break; 2414 *s++ = '\0'; 2415 } 2416 2417 if (count != macro->operands) 2418 { 2419 as_bad (_("wrong number of operands")); 2420 return; 2421 } 2422 2423 /* Work out how large the string must be (the size is unbounded 2424 because it includes user input). */ 2425 len = 0; 2426 format = macro->format; 2427 while (*format != '\0') 2428 { 2429 if (*format != '%') 2430 { 2431 ++len; 2432 ++format; 2433 } 2434 else 2435 { 2436 arg = strtol (format + 1, &send, 10); 2437 know (send != format && arg >= 0 && arg < count); 2438 len += strlen (operands[arg]); 2439 format = send; 2440 } 2441 } 2442 2443 /* Put the string together. */ 2444 complete = s = (char *) alloca (len + 1); 2445 format = macro->format; 2446 while (*format != '\0') 2447 { 2448 if (*format != '%') 2449 *s++ = *format++; 2450 else 2451 { 2452 arg = strtol (format + 1, &send, 10); 2453 strcpy (s, operands[arg]); 2454 s += strlen (s); 2455 format = send; 2456 } 2457 } 2458 *s = '\0'; 2459 2460 /* Assemble the constructed instruction. */ 2461 md_assemble (complete); 2462} 2463 2464#ifdef OBJ_ELF 2465/* For ELF, add support for SHF_EXCLUDE and SHT_ORDERED. */ 2466 2467int 2468ppc_section_letter (letter, ptr_msg) 2469 int letter; 2470 char **ptr_msg; 2471{ 2472 if (letter == 'e') 2473 return SHF_EXCLUDE; 2474 2475 *ptr_msg = _("Bad .section directive: want a,e,w,x,M,S in string"); 2476 return 0; 2477} 2478 2479int 2480ppc_section_word (str, len) 2481 char *str; 2482 size_t len; 2483{ 2484 if (len == 7 && strncmp (str, "exclude", 7) == 0) 2485 return SHF_EXCLUDE; 2486 2487 return -1; 2488} 2489 2490int 2491ppc_section_type (str, len) 2492 char *str; 2493 size_t len; 2494{ 2495 if (len == 7 && strncmp (str, "ordered", 7) == 0) 2496 return SHT_ORDERED; 2497 2498 return -1; 2499} 2500 2501int 2502ppc_section_flags (flags, attr, type) 2503 int flags; 2504 int attr; 2505 int type; 2506{ 2507 if (type == SHT_ORDERED) 2508 flags |= SEC_ALLOC | SEC_LOAD | SEC_SORT_ENTRIES; 2509 2510 if (attr & SHF_EXCLUDE) 2511 flags |= SEC_EXCLUDE; 2512 2513 return flags; 2514} 2515#endif /* OBJ_ELF */ 2516 2517 2518/* Pseudo-op handling. */ 2519 2520/* The .byte pseudo-op. This is similar to the normal .byte 2521 pseudo-op, but it can also take a single ASCII string. */ 2522 2523static void 2524ppc_byte (ignore) 2525 int ignore ATTRIBUTE_UNUSED; 2526{ 2527 if (*input_line_pointer != '\"') 2528 { 2529 cons (1); 2530 return; 2531 } 2532 2533 /* Gather characters. A real double quote is doubled. Unusual 2534 characters are not permitted. */ 2535 ++input_line_pointer; 2536 while (1) 2537 { 2538 char c; 2539 2540 c = *input_line_pointer++; 2541 2542 if (c == '\"') 2543 { 2544 if (*input_line_pointer != '\"') 2545 break; 2546 ++input_line_pointer; 2547 } 2548 2549 FRAG_APPEND_1_CHAR (c); 2550 } 2551 2552 demand_empty_rest_of_line (); 2553} 2554 2555#ifdef OBJ_XCOFF 2556 2557/* XCOFF specific pseudo-op handling. */ 2558 2559/* This is set if we are creating a .stabx symbol, since we don't want 2560 to handle symbol suffixes for such symbols. */ 2561static boolean ppc_stab_symbol; 2562 2563/* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common 2564 symbols in the .bss segment as though they were local common 2565 symbols, and uses a different smclas. The native Aix 4.3.3 assember 2566 aligns .comm and .lcomm to 4 bytes. */ 2567 2568static void 2569ppc_comm (lcomm) 2570 int lcomm; 2571{ 2572 asection *current_seg = now_seg; 2573 subsegT current_subseg = now_subseg; 2574 char *name; 2575 char endc; 2576 char *end_name; 2577 offsetT size; 2578 offsetT align; 2579 symbolS *lcomm_sym = NULL; 2580 symbolS *sym; 2581 char *pfrag; 2582 2583 name = input_line_pointer; 2584 endc = get_symbol_end (); 2585 end_name = input_line_pointer; 2586 *end_name = endc; 2587 2588 if (*input_line_pointer != ',') 2589 { 2590 as_bad (_("missing size")); 2591 ignore_rest_of_line (); 2592 return; 2593 } 2594 ++input_line_pointer; 2595 2596 size = get_absolute_expression (); 2597 if (size < 0) 2598 { 2599 as_bad (_("negative size")); 2600 ignore_rest_of_line (); 2601 return; 2602 } 2603 2604 if (! lcomm) 2605 { 2606 /* The third argument to .comm is the alignment. */ 2607 if (*input_line_pointer != ',') 2608 align = 2; 2609 else 2610 { 2611 ++input_line_pointer; 2612 align = get_absolute_expression (); 2613 if (align <= 0) 2614 { 2615 as_warn (_("ignoring bad alignment")); 2616 align = 2; 2617 } 2618 } 2619 } 2620 else 2621 { 2622 char *lcomm_name; 2623 char lcomm_endc; 2624 2625 if (size <= 4) 2626 align = 2; 2627 else 2628 align = 3; 2629 2630 /* The third argument to .lcomm appears to be the real local 2631 common symbol to create. References to the symbol named in 2632 the first argument are turned into references to the third 2633 argument. */ 2634 if (*input_line_pointer != ',') 2635 { 2636 as_bad (_("missing real symbol name")); 2637 ignore_rest_of_line (); 2638 return; 2639 } 2640 ++input_line_pointer; 2641 2642 lcomm_name = input_line_pointer; 2643 lcomm_endc = get_symbol_end (); 2644 2645 lcomm_sym = symbol_find_or_make (lcomm_name); 2646 2647 *input_line_pointer = lcomm_endc; 2648 } 2649 2650 *end_name = '\0'; 2651 sym = symbol_find_or_make (name); 2652 *end_name = endc; 2653 2654 if (S_IS_DEFINED (sym) 2655 || S_GET_VALUE (sym) != 0) 2656 { 2657 as_bad (_("attempt to redefine symbol")); 2658 ignore_rest_of_line (); 2659 return; 2660 } 2661 2662 record_alignment (bss_section, align); 2663 2664 if (! lcomm 2665 || ! S_IS_DEFINED (lcomm_sym)) 2666 { 2667 symbolS *def_sym; 2668 offsetT def_size; 2669 2670 if (! lcomm) 2671 { 2672 def_sym = sym; 2673 def_size = size; 2674 S_SET_EXTERNAL (sym); 2675 } 2676 else 2677 { 2678 symbol_get_tc (lcomm_sym)->output = 1; 2679 def_sym = lcomm_sym; 2680 def_size = 0; 2681 } 2682 2683 subseg_set (bss_section, 1); 2684 frag_align (align, 0, 0); 2685 2686 symbol_set_frag (def_sym, frag_now); 2687 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, def_sym, 2688 def_size, (char *) NULL); 2689 *pfrag = 0; 2690 S_SET_SEGMENT (def_sym, bss_section); 2691 symbol_get_tc (def_sym)->align = align; 2692 } 2693 else if (lcomm) 2694 { 2695 /* Align the size of lcomm_sym. */ 2696 symbol_get_frag (lcomm_sym)->fr_offset = 2697 ((symbol_get_frag (lcomm_sym)->fr_offset + (1 << align) - 1) 2698 &~ ((1 << align) - 1)); 2699 if (align > symbol_get_tc (lcomm_sym)->align) 2700 symbol_get_tc (lcomm_sym)->align = align; 2701 } 2702 2703 if (lcomm) 2704 { 2705 /* Make sym an offset from lcomm_sym. */ 2706 S_SET_SEGMENT (sym, bss_section); 2707 symbol_set_frag (sym, symbol_get_frag (lcomm_sym)); 2708 S_SET_VALUE (sym, symbol_get_frag (lcomm_sym)->fr_offset); 2709 symbol_get_frag (lcomm_sym)->fr_offset += size; 2710 } 2711 2712 subseg_set (current_seg, current_subseg); 2713 2714 demand_empty_rest_of_line (); 2715} 2716 2717/* The .csect pseudo-op. This switches us into a different 2718 subsegment. The first argument is a symbol whose value is the 2719 start of the .csect. In COFF, csect symbols get special aux 2720 entries defined by the x_csect field of union internal_auxent. The 2721 optional second argument is the alignment (the default is 2). */ 2722 2723static void 2724ppc_csect (ignore) 2725 int ignore ATTRIBUTE_UNUSED; 2726{ 2727 char *name; 2728 char endc; 2729 symbolS *sym; 2730 2731 name = input_line_pointer; 2732 endc = get_symbol_end (); 2733 2734 sym = symbol_find_or_make (name); 2735 2736 *input_line_pointer = endc; 2737 2738 if (S_GET_NAME (sym)[0] == '\0') 2739 { 2740 /* An unnamed csect is assumed to be [PR]. */ 2741 symbol_get_tc (sym)->class = XMC_PR; 2742 } 2743 2744 ppc_change_csect (sym); 2745 2746 if (*input_line_pointer == ',') 2747 { 2748 ++input_line_pointer; 2749 symbol_get_tc (sym)->align = get_absolute_expression (); 2750 } 2751 2752 demand_empty_rest_of_line (); 2753} 2754 2755/* Change to a different csect. */ 2756 2757static void 2758ppc_change_csect (sym) 2759 symbolS *sym; 2760{ 2761 if (S_IS_DEFINED (sym)) 2762 subseg_set (S_GET_SEGMENT (sym), symbol_get_tc (sym)->subseg); 2763 else 2764 { 2765 symbolS **list_ptr; 2766 int after_toc; 2767 int hold_chunksize; 2768 symbolS *list; 2769 2770 /* This is a new csect. We need to look at the symbol class to 2771 figure out whether it should go in the text section or the 2772 data section. */ 2773 after_toc = 0; 2774 switch (symbol_get_tc (sym)->class) 2775 { 2776 case XMC_PR: 2777 case XMC_RO: 2778 case XMC_DB: 2779 case XMC_GL: 2780 case XMC_XO: 2781 case XMC_SV: 2782 case XMC_TI: 2783 case XMC_TB: 2784 S_SET_SEGMENT (sym, text_section); 2785 symbol_get_tc (sym)->subseg = ppc_text_subsegment; 2786 ++ppc_text_subsegment; 2787 list_ptr = &ppc_text_csects; 2788 break; 2789 case XMC_RW: 2790 case XMC_TC0: 2791 case XMC_TC: 2792 case XMC_DS: 2793 case XMC_UA: 2794 case XMC_BS: 2795 case XMC_UC: 2796 if (ppc_toc_csect != NULL 2797 && (symbol_get_tc (ppc_toc_csect)->subseg + 1 2798 == ppc_data_subsegment)) 2799 after_toc = 1; 2800 S_SET_SEGMENT (sym, data_section); 2801 symbol_get_tc (sym)->subseg = ppc_data_subsegment; 2802 ++ppc_data_subsegment; 2803 list_ptr = &ppc_data_csects; 2804 break; 2805 default: 2806 abort (); 2807 } 2808 2809 /* We set the obstack chunk size to a small value before 2810 changing subsegments, so that we don't use a lot of memory 2811 space for what may be a small section. */ 2812 hold_chunksize = chunksize; 2813 chunksize = 64; 2814 2815 subseg_new (segment_name (S_GET_SEGMENT (sym)), 2816 symbol_get_tc (sym)->subseg); 2817 2818 chunksize = hold_chunksize; 2819 2820 if (after_toc) 2821 ppc_after_toc_frag = frag_now; 2822 2823 symbol_set_frag (sym, frag_now); 2824 S_SET_VALUE (sym, (valueT) frag_now_fix ()); 2825 2826 symbol_get_tc (sym)->align = (ppc_xcoff64) ? 3 : 2; 2827 symbol_get_tc (sym)->output = 1; 2828 symbol_get_tc (sym)->within = sym; 2829 2830 for (list = *list_ptr; 2831 symbol_get_tc (list)->next != (symbolS *) NULL; 2832 list = symbol_get_tc (list)->next) 2833 ; 2834 symbol_get_tc (list)->next = sym; 2835 2836 symbol_remove (sym, &symbol_rootP, &symbol_lastP); 2837 symbol_append (sym, symbol_get_tc (list)->within, &symbol_rootP, 2838 &symbol_lastP); 2839 } 2840 2841 ppc_current_csect = sym; 2842} 2843 2844/* This function handles the .text and .data pseudo-ops. These 2845 pseudo-ops aren't really used by XCOFF; we implement them for the 2846 convenience of people who aren't used to XCOFF. */ 2847 2848static void 2849ppc_section (type) 2850 int type; 2851{ 2852 const char *name; 2853 symbolS *sym; 2854 2855 if (type == 't') 2856 name = ".text[PR]"; 2857 else if (type == 'd') 2858 name = ".data[RW]"; 2859 else 2860 abort (); 2861 2862 sym = symbol_find_or_make (name); 2863 2864 ppc_change_csect (sym); 2865 2866 demand_empty_rest_of_line (); 2867} 2868 2869/* This function handles the .section pseudo-op. This is mostly to 2870 give an error, since XCOFF only supports .text, .data and .bss, but 2871 we do permit the user to name the text or data section. */ 2872 2873static void 2874ppc_named_section (ignore) 2875 int ignore ATTRIBUTE_UNUSED; 2876{ 2877 char *user_name; 2878 const char *real_name; 2879 char c; 2880 symbolS *sym; 2881 2882 user_name = input_line_pointer; 2883 c = get_symbol_end (); 2884 2885 if (strcmp (user_name, ".text") == 0) 2886 real_name = ".text[PR]"; 2887 else if (strcmp (user_name, ".data") == 0) 2888 real_name = ".data[RW]"; 2889 else 2890 { 2891 as_bad (_("The XCOFF file format does not support arbitrary sections")); 2892 *input_line_pointer = c; 2893 ignore_rest_of_line (); 2894 return; 2895 } 2896 2897 *input_line_pointer = c; 2898 2899 sym = symbol_find_or_make (real_name); 2900 2901 ppc_change_csect (sym); 2902 2903 demand_empty_rest_of_line (); 2904} 2905 2906/* The .extern pseudo-op. We create an undefined symbol. */ 2907 2908static void 2909ppc_extern (ignore) 2910 int ignore ATTRIBUTE_UNUSED; 2911{ 2912 char *name; 2913 char endc; 2914 2915 name = input_line_pointer; 2916 endc = get_symbol_end (); 2917 2918 (void) symbol_find_or_make (name); 2919 2920 *input_line_pointer = endc; 2921 2922 demand_empty_rest_of_line (); 2923} 2924 2925/* The .lglobl pseudo-op. Keep the symbol in the symbol table. */ 2926 2927static void 2928ppc_lglobl (ignore) 2929 int ignore ATTRIBUTE_UNUSED; 2930{ 2931 char *name; 2932 char endc; 2933 symbolS *sym; 2934 2935 name = input_line_pointer; 2936 endc = get_symbol_end (); 2937 2938 sym = symbol_find_or_make (name); 2939 2940 *input_line_pointer = endc; 2941 2942 symbol_get_tc (sym)->output = 1; 2943 2944 demand_empty_rest_of_line (); 2945} 2946 2947/* The .rename pseudo-op. The RS/6000 assembler can rename symbols, 2948 although I don't know why it bothers. */ 2949 2950static void 2951ppc_rename (ignore) 2952 int ignore ATTRIBUTE_UNUSED; 2953{ 2954 char *name; 2955 char endc; 2956 symbolS *sym; 2957 int len; 2958 2959 name = input_line_pointer; 2960 endc = get_symbol_end (); 2961 2962 sym = symbol_find_or_make (name); 2963 2964 *input_line_pointer = endc; 2965 2966 if (*input_line_pointer != ',') 2967 { 2968 as_bad (_("missing rename string")); 2969 ignore_rest_of_line (); 2970 return; 2971 } 2972 ++input_line_pointer; 2973 2974 symbol_get_tc (sym)->real_name = demand_copy_C_string (&len); 2975 2976 demand_empty_rest_of_line (); 2977} 2978 2979/* The .stabx pseudo-op. This is similar to a normal .stabs 2980 pseudo-op, but slightly different. A sample is 2981 .stabx "main:F-1",.main,142,0 2982 The first argument is the symbol name to create. The second is the 2983 value, and the third is the storage class. The fourth seems to be 2984 always zero, and I am assuming it is the type. */ 2985 2986static void 2987ppc_stabx (ignore) 2988 int ignore ATTRIBUTE_UNUSED; 2989{ 2990 char *name; 2991 int len; 2992 symbolS *sym; 2993 expressionS exp; 2994 2995 name = demand_copy_C_string (&len); 2996 2997 if (*input_line_pointer != ',') 2998 { 2999 as_bad (_("missing value")); 3000 return; 3001 } 3002 ++input_line_pointer; 3003 3004 ppc_stab_symbol = true; 3005 sym = symbol_make (name); 3006 ppc_stab_symbol = false; 3007 3008 symbol_get_tc (sym)->real_name = name; 3009 3010 (void) expression (&exp); 3011 3012 switch (exp.X_op) 3013 { 3014 case O_illegal: 3015 case O_absent: 3016 case O_big: 3017 as_bad (_("illegal .stabx expression; zero assumed")); 3018 exp.X_add_number = 0; 3019 /* Fall through. */ 3020 case O_constant: 3021 S_SET_VALUE (sym, (valueT) exp.X_add_number); 3022 symbol_set_frag (sym, &zero_address_frag); 3023 break; 3024 3025 case O_symbol: 3026 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section) 3027 symbol_set_value_expression (sym, &exp); 3028 else 3029 { 3030 S_SET_VALUE (sym, 3031 exp.X_add_number + S_GET_VALUE (exp.X_add_symbol)); 3032 symbol_set_frag (sym, symbol_get_frag (exp.X_add_symbol)); 3033 } 3034 break; 3035 3036 default: 3037 /* The value is some complex expression. This will probably 3038 fail at some later point, but this is probably the right 3039 thing to do here. */ 3040 symbol_set_value_expression (sym, &exp); 3041 break; 3042 } 3043 3044 S_SET_SEGMENT (sym, ppc_coff_debug_section); 3045 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING; 3046 3047 if (*input_line_pointer != ',') 3048 { 3049 as_bad (_("missing class")); 3050 return; 3051 } 3052 ++input_line_pointer; 3053 3054 S_SET_STORAGE_CLASS (sym, get_absolute_expression ()); 3055 3056 if (*input_line_pointer != ',') 3057 { 3058 as_bad (_("missing type")); 3059 return; 3060 } 3061 ++input_line_pointer; 3062 3063 S_SET_DATA_TYPE (sym, get_absolute_expression ()); 3064 3065 symbol_get_tc (sym)->output = 1; 3066 3067 if (S_GET_STORAGE_CLASS (sym) == C_STSYM) { 3068 3069 symbol_get_tc (sym)->within = ppc_current_block; 3070 3071 /* In this case : 3072 3073 .bs name 3074 .stabx "z",arrays_,133,0 3075 .es 3076 3077 .comm arrays_,13768,3 3078 3079 resolve_symbol_value will copy the exp's "within" into sym's when the 3080 offset is 0. Since this seems to be corner case problem, 3081 only do the correction for storage class C_STSYM. A better solution 3082 would be to have the tc field updated in ppc_symbol_new_hook. */ 3083 3084 if (exp.X_op == O_symbol) 3085 { 3086 symbol_get_tc (exp.X_add_symbol)->within = ppc_current_block; 3087 } 3088 } 3089 3090 if (exp.X_op != O_symbol 3091 || ! S_IS_EXTERNAL (exp.X_add_symbol) 3092 || S_GET_SEGMENT (exp.X_add_symbol) != bss_section) 3093 ppc_frob_label (sym); 3094 else 3095 { 3096 symbol_remove (sym, &symbol_rootP, &symbol_lastP); 3097 symbol_append (sym, exp.X_add_symbol, &symbol_rootP, &symbol_lastP); 3098 if (symbol_get_tc (ppc_current_csect)->within == exp.X_add_symbol) 3099 symbol_get_tc (ppc_current_csect)->within = sym; 3100 } 3101 3102 demand_empty_rest_of_line (); 3103} 3104 3105/* The .function pseudo-op. This takes several arguments. The first 3106 argument seems to be the external name of the symbol. The second 3107 argment seems to be the label for the start of the function. gcc 3108 uses the same name for both. I have no idea what the third and 3109 fourth arguments are meant to be. The optional fifth argument is 3110 an expression for the size of the function. In COFF this symbol 3111 gets an aux entry like that used for a csect. */ 3112 3113static void 3114ppc_function (ignore) 3115 int ignore ATTRIBUTE_UNUSED; 3116{ 3117 char *name; 3118 char endc; 3119 char *s; 3120 symbolS *ext_sym; 3121 symbolS *lab_sym; 3122 3123 name = input_line_pointer; 3124 endc = get_symbol_end (); 3125 3126 /* Ignore any [PR] suffix. */ 3127 name = ppc_canonicalize_symbol_name (name); 3128 s = strchr (name, '['); 3129 if (s != (char *) NULL 3130 && strcmp (s + 1, "PR]") == 0) 3131 *s = '\0'; 3132 3133 ext_sym = symbol_find_or_make (name); 3134 3135 *input_line_pointer = endc; 3136 3137 if (*input_line_pointer != ',') 3138 { 3139 as_bad (_("missing symbol name")); 3140 ignore_rest_of_line (); 3141 return; 3142 } 3143 ++input_line_pointer; 3144 3145 name = input_line_pointer; 3146 endc = get_symbol_end (); 3147 3148 lab_sym = symbol_find_or_make (name); 3149 3150 *input_line_pointer = endc; 3151 3152 if (ext_sym != lab_sym) 3153 { 3154 expressionS exp; 3155 3156 exp.X_op = O_symbol; 3157 exp.X_add_symbol = lab_sym; 3158 exp.X_op_symbol = NULL; 3159 exp.X_add_number = 0; 3160 exp.X_unsigned = 0; 3161 symbol_set_value_expression (ext_sym, &exp); 3162 } 3163 3164 if (symbol_get_tc (ext_sym)->class == -1) 3165 symbol_get_tc (ext_sym)->class = XMC_PR; 3166 symbol_get_tc (ext_sym)->output = 1; 3167 3168 if (*input_line_pointer == ',') 3169 { 3170 expressionS ignore; 3171 3172 /* Ignore the third argument. */ 3173 ++input_line_pointer; 3174 expression (&ignore); 3175 if (*input_line_pointer == ',') 3176 { 3177 /* Ignore the fourth argument. */ 3178 ++input_line_pointer; 3179 expression (&ignore); 3180 if (*input_line_pointer == ',') 3181 { 3182 /* The fifth argument is the function size. */ 3183 ++input_line_pointer; 3184 symbol_get_tc (ext_sym)->size = symbol_new ("L0\001", 3185 absolute_section, 3186 (valueT) 0, 3187 &zero_address_frag); 3188 pseudo_set (symbol_get_tc (ext_sym)->size); 3189 } 3190 } 3191 } 3192 3193 S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT); 3194 SF_SET_FUNCTION (ext_sym); 3195 SF_SET_PROCESS (ext_sym); 3196 coff_add_linesym (ext_sym); 3197 3198 demand_empty_rest_of_line (); 3199} 3200 3201/* The .bf pseudo-op. This is just like a COFF C_FCN symbol named 3202 ".bf". If the pseudo op .bi was seen before .bf, patch the .bi sym 3203 with the correct line number */ 3204 3205static symbolS *saved_bi_sym = 0; 3206 3207static void 3208ppc_bf (ignore) 3209 int ignore ATTRIBUTE_UNUSED; 3210{ 3211 symbolS *sym; 3212 3213 sym = symbol_make (".bf"); 3214 S_SET_SEGMENT (sym, text_section); 3215 symbol_set_frag (sym, frag_now); 3216 S_SET_VALUE (sym, frag_now_fix ()); 3217 S_SET_STORAGE_CLASS (sym, C_FCN); 3218 3219 coff_line_base = get_absolute_expression (); 3220 3221 S_SET_NUMBER_AUXILIARY (sym, 1); 3222 SA_SET_SYM_LNNO (sym, coff_line_base); 3223 3224 /* Line number for bi. */ 3225 if (saved_bi_sym) 3226 { 3227 S_SET_VALUE (saved_bi_sym, coff_n_line_nos); 3228 saved_bi_sym = 0; 3229 } 3230 3231 3232 symbol_get_tc (sym)->output = 1; 3233 3234 ppc_frob_label (sym); 3235 3236 demand_empty_rest_of_line (); 3237} 3238 3239/* The .ef pseudo-op. This is just like a COFF C_FCN symbol named 3240 ".ef", except that the line number is absolute, not relative to the 3241 most recent ".bf" symbol. */ 3242 3243static void 3244ppc_ef (ignore) 3245 int ignore ATTRIBUTE_UNUSED; 3246{ 3247 symbolS *sym; 3248 3249 sym = symbol_make (".ef"); 3250 S_SET_SEGMENT (sym, text_section); 3251 symbol_set_frag (sym, frag_now); 3252 S_SET_VALUE (sym, frag_now_fix ()); 3253 S_SET_STORAGE_CLASS (sym, C_FCN); 3254 S_SET_NUMBER_AUXILIARY (sym, 1); 3255 SA_SET_SYM_LNNO (sym, get_absolute_expression ()); 3256 symbol_get_tc (sym)->output = 1; 3257 3258 ppc_frob_label (sym); 3259 3260 demand_empty_rest_of_line (); 3261} 3262 3263/* The .bi and .ei pseudo-ops. These take a string argument and 3264 generates a C_BINCL or C_EINCL symbol, which goes at the start of 3265 the symbol list. The value of .bi will be know when the next .bf 3266 is encountered. */ 3267 3268static void 3269ppc_biei (ei) 3270 int ei; 3271{ 3272 static symbolS *last_biei; 3273 3274 char *name; 3275 int len; 3276 symbolS *sym; 3277 symbolS *look; 3278 3279 name = demand_copy_C_string (&len); 3280 3281 /* The value of these symbols is actually file offset. Here we set 3282 the value to the index into the line number entries. In 3283 ppc_frob_symbols we set the fix_line field, which will cause BFD 3284 to do the right thing. */ 3285 3286 sym = symbol_make (name); 3287 /* obj-coff.c currently only handles line numbers correctly in the 3288 .text section. */ 3289 S_SET_SEGMENT (sym, text_section); 3290 S_SET_VALUE (sym, coff_n_line_nos); 3291 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING; 3292 3293 S_SET_STORAGE_CLASS (sym, ei ? C_EINCL : C_BINCL); 3294 symbol_get_tc (sym)->output = 1; 3295 3296 /* Save bi. */ 3297 if (ei) 3298 saved_bi_sym = 0; 3299 else 3300 saved_bi_sym = sym; 3301 3302 for (look = last_biei ? last_biei : symbol_rootP; 3303 (look != (symbolS *) NULL 3304 && (S_GET_STORAGE_CLASS (look) == C_FILE 3305 || S_GET_STORAGE_CLASS (look) == C_BINCL 3306 || S_GET_STORAGE_CLASS (look) == C_EINCL)); 3307 look = symbol_next (look)) 3308 ; 3309 if (look != (symbolS *) NULL) 3310 { 3311 symbol_remove (sym, &symbol_rootP, &symbol_lastP); 3312 symbol_insert (sym, look, &symbol_rootP, &symbol_lastP); 3313 last_biei = sym; 3314 } 3315 3316 demand_empty_rest_of_line (); 3317} 3318 3319/* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs". 3320 There is one argument, which is a csect symbol. The value of the 3321 .bs symbol is the index of this csect symbol. */ 3322 3323static void 3324ppc_bs (ignore) 3325 int ignore ATTRIBUTE_UNUSED; 3326{ 3327 char *name; 3328 char endc; 3329 symbolS *csect; 3330 symbolS *sym; 3331 3332 if (ppc_current_block != NULL) 3333 as_bad (_("nested .bs blocks")); 3334 3335 name = input_line_pointer; 3336 endc = get_symbol_end (); 3337 3338 csect = symbol_find_or_make (name); 3339 3340 *input_line_pointer = endc; 3341 3342 sym = symbol_make (".bs"); 3343 S_SET_SEGMENT (sym, now_seg); 3344 S_SET_STORAGE_CLASS (sym, C_BSTAT); 3345 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING; 3346 symbol_get_tc (sym)->output = 1; 3347 3348 symbol_get_tc (sym)->within = csect; 3349 3350 ppc_frob_label (sym); 3351 3352 ppc_current_block = sym; 3353 3354 demand_empty_rest_of_line (); 3355} 3356 3357/* The .es pseudo-op. Generate a C_ESTART symbol named .es. */ 3358 3359static void 3360ppc_es (ignore) 3361 int ignore ATTRIBUTE_UNUSED; 3362{ 3363 symbolS *sym; 3364 3365 if (ppc_current_block == NULL) 3366 as_bad (_(".es without preceding .bs")); 3367 3368 sym = symbol_make (".es"); 3369 S_SET_SEGMENT (sym, now_seg); 3370 S_SET_STORAGE_CLASS (sym, C_ESTAT); 3371 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING; 3372 symbol_get_tc (sym)->output = 1; 3373 3374 ppc_frob_label (sym); 3375 3376 ppc_current_block = NULL; 3377 3378 demand_empty_rest_of_line (); 3379} 3380 3381/* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a 3382 line number. */ 3383 3384static void 3385ppc_bb (ignore) 3386 int ignore ATTRIBUTE_UNUSED; 3387{ 3388 symbolS *sym; 3389 3390 sym = symbol_make (".bb"); 3391 S_SET_SEGMENT (sym, text_section); 3392 symbol_set_frag (sym, frag_now); 3393 S_SET_VALUE (sym, frag_now_fix ()); 3394 S_SET_STORAGE_CLASS (sym, C_BLOCK); 3395 3396 S_SET_NUMBER_AUXILIARY (sym, 1); 3397 SA_SET_SYM_LNNO (sym, get_absolute_expression ()); 3398 3399 symbol_get_tc (sym)->output = 1; 3400 3401 SF_SET_PROCESS (sym); 3402 3403 ppc_frob_label (sym); 3404 3405 demand_empty_rest_of_line (); 3406} 3407 3408/* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a 3409 line number. */ 3410 3411static void 3412ppc_eb (ignore) 3413 int ignore ATTRIBUTE_UNUSED; 3414{ 3415 symbolS *sym; 3416 3417 sym = symbol_make (".eb"); 3418 S_SET_SEGMENT (sym, text_section); 3419 symbol_set_frag (sym, frag_now); 3420 S_SET_VALUE (sym, frag_now_fix ()); 3421 S_SET_STORAGE_CLASS (sym, C_BLOCK); 3422 S_SET_NUMBER_AUXILIARY (sym, 1); 3423 SA_SET_SYM_LNNO (sym, get_absolute_expression ()); 3424 symbol_get_tc (sym)->output = 1; 3425 3426 SF_SET_PROCESS (sym); 3427 3428 ppc_frob_label (sym); 3429 3430 demand_empty_rest_of_line (); 3431} 3432 3433/* The .bc pseudo-op. This just creates a C_BCOMM symbol with a 3434 specified name. */ 3435 3436static void 3437ppc_bc (ignore) 3438 int ignore ATTRIBUTE_UNUSED; 3439{ 3440 char *name; 3441 int len; 3442 symbolS *sym; 3443 3444 name = demand_copy_C_string (&len); 3445 sym = symbol_make (name); 3446 S_SET_SEGMENT (sym, ppc_coff_debug_section); 3447 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING; 3448 S_SET_STORAGE_CLASS (sym, C_BCOMM); 3449 S_SET_VALUE (sym, 0); 3450 symbol_get_tc (sym)->output = 1; 3451 3452 ppc_frob_label (sym); 3453 3454 demand_empty_rest_of_line (); 3455} 3456 3457/* The .ec pseudo-op. This just creates a C_ECOMM symbol. */ 3458 3459static void 3460ppc_ec (ignore) 3461 int ignore ATTRIBUTE_UNUSED; 3462{ 3463 symbolS *sym; 3464 3465 sym = symbol_make (".ec"); 3466 S_SET_SEGMENT (sym, ppc_coff_debug_section); 3467 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING; 3468 S_SET_STORAGE_CLASS (sym, C_ECOMM); 3469 S_SET_VALUE (sym, 0); 3470 symbol_get_tc (sym)->output = 1; 3471 3472 ppc_frob_label (sym); 3473 3474 demand_empty_rest_of_line (); 3475} 3476 3477/* The .toc pseudo-op. Switch to the .toc subsegment. */ 3478 3479static void 3480ppc_toc (ignore) 3481 int ignore ATTRIBUTE_UNUSED; 3482{ 3483 if (ppc_toc_csect != (symbolS *) NULL) 3484 subseg_set (data_section, symbol_get_tc (ppc_toc_csect)->subseg); 3485 else 3486 { 3487 subsegT subseg; 3488 symbolS *sym; 3489 symbolS *list; 3490 3491 subseg = ppc_data_subsegment; 3492 ++ppc_data_subsegment; 3493 3494 subseg_new (segment_name (data_section), subseg); 3495 ppc_toc_frag = frag_now; 3496 3497 sym = symbol_find_or_make ("TOC[TC0]"); 3498 symbol_set_frag (sym, frag_now); 3499 S_SET_SEGMENT (sym, data_section); 3500 S_SET_VALUE (sym, (valueT) frag_now_fix ()); 3501 symbol_get_tc (sym)->subseg = subseg; 3502 symbol_get_tc (sym)->output = 1; 3503 symbol_get_tc (sym)->within = sym; 3504 3505 ppc_toc_csect = sym; 3506 3507 for (list = ppc_data_csects; 3508 symbol_get_tc (list)->next != (symbolS *) NULL; 3509 list = symbol_get_tc (list)->next) 3510 ; 3511 symbol_get_tc (list)->next = sym; 3512 3513 symbol_remove (sym, &symbol_rootP, &symbol_lastP); 3514 symbol_append (sym, symbol_get_tc (list)->within, &symbol_rootP, 3515 &symbol_lastP); 3516 } 3517 3518 ppc_current_csect = ppc_toc_csect; 3519 3520 demand_empty_rest_of_line (); 3521} 3522 3523/* The AIX assembler automatically aligns the operands of a .long or 3524 .short pseudo-op, and we want to be compatible. */ 3525 3526static void 3527ppc_xcoff_cons (log_size) 3528 int log_size; 3529{ 3530 frag_align (log_size, 0, 0); 3531 record_alignment (now_seg, log_size); 3532 cons (1 << log_size); 3533} 3534 3535static void 3536ppc_vbyte (dummy) 3537 int dummy ATTRIBUTE_UNUSED; 3538{ 3539 expressionS exp; 3540 int byte_count; 3541 3542 (void) expression (&exp); 3543 3544 if (exp.X_op != O_constant) 3545 { 3546 as_bad (_("non-constant byte count")); 3547 return; 3548 } 3549 3550 byte_count = exp.X_add_number; 3551 3552 if (*input_line_pointer != ',') 3553 { 3554 as_bad (_("missing value")); 3555 return; 3556 } 3557 3558 ++input_line_pointer; 3559 cons (byte_count); 3560} 3561 3562#endif /* OBJ_XCOFF */ 3563#if defined (OBJ_XCOFF) || defined (OBJ_ELF) 3564 3565/* The .tc pseudo-op. This is used when generating either XCOFF or 3566 ELF. This takes two or more arguments. 3567 3568 When generating XCOFF output, the first argument is the name to 3569 give to this location in the toc; this will be a symbol with class 3570 TC. The rest of the arguments are N-byte values to actually put at 3571 this location in the TOC; often there is just one more argument, a 3572 relocateable symbol reference. The size of the value to store 3573 depends on target word size. A 32-bit target uses 4-byte values, a 3574 64-bit target uses 8-byte values. 3575 3576 When not generating XCOFF output, the arguments are the same, but 3577 the first argument is simply ignored. */ 3578 3579static void 3580ppc_tc (ignore) 3581 int ignore ATTRIBUTE_UNUSED; 3582{ 3583#ifdef OBJ_XCOFF 3584 3585 /* Define the TOC symbol name. */ 3586 { 3587 char *name; 3588 char endc; 3589 symbolS *sym; 3590 3591 if (ppc_toc_csect == (symbolS *) NULL 3592 || ppc_toc_csect != ppc_current_csect) 3593 { 3594 as_bad (_(".tc not in .toc section")); 3595 ignore_rest_of_line (); 3596 return; 3597 } 3598 3599 name = input_line_pointer; 3600 endc = get_symbol_end (); 3601 3602 sym = symbol_find_or_make (name); 3603 3604 *input_line_pointer = endc; 3605 3606 if (S_IS_DEFINED (sym)) 3607 { 3608 symbolS *label; 3609 3610 label = symbol_get_tc (ppc_current_csect)->within; 3611 if (symbol_get_tc (label)->class != XMC_TC0) 3612 { 3613 as_bad (_(".tc with no label")); 3614 ignore_rest_of_line (); 3615 return; 3616 } 3617 3618 S_SET_SEGMENT (label, S_GET_SEGMENT (sym)); 3619 symbol_set_frag (label, symbol_get_frag (sym)); 3620 S_SET_VALUE (label, S_GET_VALUE (sym)); 3621 3622 while (! is_end_of_line[(unsigned char) *input_line_pointer]) 3623 ++input_line_pointer; 3624 3625 return; 3626 } 3627 3628 S_SET_SEGMENT (sym, now_seg); 3629 symbol_set_frag (sym, frag_now); 3630 S_SET_VALUE (sym, (valueT) frag_now_fix ()); 3631 symbol_get_tc (sym)->class = XMC_TC; 3632 symbol_get_tc (sym)->output = 1; 3633 3634 ppc_frob_label (sym); 3635 } 3636 3637#endif /* OBJ_XCOFF */ 3638#ifdef OBJ_ELF 3639 int align; 3640 3641 /* Skip the TOC symbol name. */ 3642 while (is_part_of_name (*input_line_pointer) 3643 || *input_line_pointer == '[' 3644 || *input_line_pointer == ']' 3645 || *input_line_pointer == '{' 3646 || *input_line_pointer == '}') 3647 ++input_line_pointer; 3648 3649 /* Align to a four/eight byte boundary. */ 3650 align = BFD_DEFAULT_TARGET_SIZE == 64 && ppc_size == PPC_OPCODE_64 ? 3 : 2; 3651 frag_align (align, 0, 0); 3652 record_alignment (now_seg, align); 3653#endif /* OBJ_ELF */ 3654 3655 if (*input_line_pointer != ',') 3656 demand_empty_rest_of_line (); 3657 else 3658 { 3659 ++input_line_pointer; 3660 cons ((ppc_size == PPC_OPCODE_64) ? 8 : 4); 3661 } 3662} 3663 3664/* Pseudo-op .machine. */ 3665/* FIXME: `.machine' is a nop for the moment. It would be nice to 3666 accept this directive on the first line of input and set ppc_size 3667 and the target format accordingly. Unfortunately, the target 3668 format is selected in output-file.c:output_file_create before we 3669 even get to md_begin, so it's not possible without changing 3670 as.c:main. */ 3671 3672static void 3673ppc_machine (ignore) 3674 int ignore ATTRIBUTE_UNUSED; 3675{ 3676 discard_rest_of_line (); 3677} 3678 3679/* See whether a symbol is in the TOC section. */ 3680 3681static int 3682ppc_is_toc_sym (sym) 3683 symbolS *sym; 3684{ 3685#ifdef OBJ_XCOFF 3686 return symbol_get_tc (sym)->class == XMC_TC; 3687#endif 3688#ifdef OBJ_ELF 3689 const char *sname = segment_name (S_GET_SEGMENT (sym)); 3690 if (BFD_DEFAULT_TARGET_SIZE == 64 && ppc_size == PPC_OPCODE_64) 3691 return strcmp (sname, ".toc") == 0; 3692 else 3693 return strcmp (sname, ".got") == 0; 3694#endif 3695} 3696#endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */ 3697 3698#ifdef TE_PE 3699 3700/* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format. */ 3701 3702/* Set the current section. */ 3703static void 3704ppc_set_current_section (new) 3705 segT new; 3706{ 3707 ppc_previous_section = ppc_current_section; 3708 ppc_current_section = new; 3709} 3710 3711/* pseudo-op: .previous 3712 behaviour: toggles the current section with the previous section. 3713 errors: None 3714 warnings: "No previous section" */ 3715 3716static void 3717ppc_previous (ignore) 3718 int ignore ATTRIBUTE_UNUSED; 3719{ 3720 symbolS *tmp; 3721 3722 if (ppc_previous_section == NULL) 3723 { 3724 as_warn (_("No previous section to return to. Directive ignored.")); 3725 return; 3726 } 3727 3728 subseg_set (ppc_previous_section, 0); 3729 3730 ppc_set_current_section (ppc_previous_section); 3731} 3732 3733/* pseudo-op: .pdata 3734 behaviour: predefined read only data section 3735 double word aligned 3736 errors: None 3737 warnings: None 3738 initial: .section .pdata "adr3" 3739 a - don't know -- maybe a misprint 3740 d - initialized data 3741 r - readable 3742 3 - double word aligned (that would be 4 byte boundary) 3743 3744 commentary: 3745 Tag index tables (also known as the function table) for exception 3746 handling, debugging, etc. */ 3747 3748static void 3749ppc_pdata (ignore) 3750 int ignore ATTRIBUTE_UNUSED; 3751{ 3752 if (pdata_section == 0) 3753 { 3754 pdata_section = subseg_new (".pdata", 0); 3755 3756 bfd_set_section_flags (stdoutput, pdata_section, 3757 (SEC_ALLOC | SEC_LOAD | SEC_RELOC 3758 | SEC_READONLY | SEC_DATA )); 3759 3760 bfd_set_section_alignment (stdoutput, pdata_section, 2); 3761 } 3762 else 3763 { 3764 pdata_section = subseg_new (".pdata", 0); 3765 } 3766 ppc_set_current_section (pdata_section); 3767} 3768 3769/* pseudo-op: .ydata 3770 behaviour: predefined read only data section 3771 double word aligned 3772 errors: None 3773 warnings: None 3774 initial: .section .ydata "drw3" 3775 a - don't know -- maybe a misprint 3776 d - initialized data 3777 r - readable 3778 3 - double word aligned (that would be 4 byte boundary) 3779 commentary: 3780 Tag tables (also known as the scope table) for exception handling, 3781 debugging, etc. */ 3782 3783static void 3784ppc_ydata (ignore) 3785 int ignore ATTRIBUTE_UNUSED; 3786{ 3787 if (ydata_section == 0) 3788 { 3789 ydata_section = subseg_new (".ydata", 0); 3790 bfd_set_section_flags (stdoutput, ydata_section, 3791 (SEC_ALLOC | SEC_LOAD | SEC_RELOC 3792 | SEC_READONLY | SEC_DATA )); 3793 3794 bfd_set_section_alignment (stdoutput, ydata_section, 3); 3795 } 3796 else 3797 { 3798 ydata_section = subseg_new (".ydata", 0); 3799 } 3800 ppc_set_current_section (ydata_section); 3801} 3802 3803/* pseudo-op: .reldata 3804 behaviour: predefined read write data section 3805 double word aligned (4-byte) 3806 FIXME: relocation is applied to it 3807 FIXME: what's the difference between this and .data? 3808 errors: None 3809 warnings: None 3810 initial: .section .reldata "drw3" 3811 d - initialized data 3812 r - readable 3813 w - writeable 3814 3 - double word aligned (that would be 8 byte boundary) 3815 3816 commentary: 3817 Like .data, but intended to hold data subject to relocation, such as 3818 function descriptors, etc. */ 3819 3820static void 3821ppc_reldata (ignore) 3822 int ignore ATTRIBUTE_UNUSED; 3823{ 3824 if (reldata_section == 0) 3825 { 3826 reldata_section = subseg_new (".reldata", 0); 3827 3828 bfd_set_section_flags (stdoutput, reldata_section, 3829 (SEC_ALLOC | SEC_LOAD | SEC_RELOC 3830 | SEC_DATA)); 3831 3832 bfd_set_section_alignment (stdoutput, reldata_section, 2); 3833 } 3834 else 3835 { 3836 reldata_section = subseg_new (".reldata", 0); 3837 } 3838 ppc_set_current_section (reldata_section); 3839} 3840 3841/* pseudo-op: .rdata 3842 behaviour: predefined read only data section 3843 double word aligned 3844 errors: None 3845 warnings: None 3846 initial: .section .rdata "dr3" 3847 d - initialized data 3848 r - readable 3849 3 - double word aligned (that would be 4 byte boundary) */ 3850 3851static void 3852ppc_rdata (ignore) 3853 int ignore ATTRIBUTE_UNUSED; 3854{ 3855 if (rdata_section == 0) 3856 { 3857 rdata_section = subseg_new (".rdata", 0); 3858 bfd_set_section_flags (stdoutput, rdata_section, 3859 (SEC_ALLOC | SEC_LOAD | SEC_RELOC 3860 | SEC_READONLY | SEC_DATA )); 3861 3862 bfd_set_section_alignment (stdoutput, rdata_section, 2); 3863 } 3864 else 3865 { 3866 rdata_section = subseg_new (".rdata", 0); 3867 } 3868 ppc_set_current_section (rdata_section); 3869} 3870 3871/* pseudo-op: .ualong 3872 behaviour: much like .int, with the exception that no alignment is 3873 performed. 3874 FIXME: test the alignment statement 3875 errors: None 3876 warnings: None */ 3877 3878static void 3879ppc_ualong (ignore) 3880 int ignore ATTRIBUTE_UNUSED; 3881{ 3882 /* Try for long. */ 3883 cons (4); 3884} 3885 3886/* pseudo-op: .znop <symbol name> 3887 behaviour: Issue a nop instruction 3888 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using 3889 the supplied symbol name. 3890 errors: None 3891 warnings: Missing symbol name */ 3892 3893static void 3894ppc_znop (ignore) 3895 int ignore ATTRIBUTE_UNUSED; 3896{ 3897 unsigned long insn; 3898 const struct powerpc_opcode *opcode; 3899 expressionS ex; 3900 char *f; 3901 symbolS *sym; 3902 char *symbol_name; 3903 char c; 3904 char *name; 3905 unsigned int exp; 3906 flagword flags; 3907 asection *sec; 3908 3909 /* Strip out the symbol name. */ 3910 symbol_name = input_line_pointer; 3911 c = get_symbol_end (); 3912 3913 name = xmalloc (input_line_pointer - symbol_name + 1); 3914 strcpy (name, symbol_name); 3915 3916 sym = symbol_find_or_make (name); 3917 3918 *input_line_pointer = c; 3919 3920 SKIP_WHITESPACE (); 3921 3922 /* Look up the opcode in the hash table. */ 3923 opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, "nop"); 3924 3925 /* Stick in the nop. */ 3926 insn = opcode->opcode; 3927 3928 /* Write out the instruction. */ 3929 f = frag_more (4); 3930 md_number_to_chars (f, insn, 4); 3931 fix_new (frag_now, 3932 f - frag_now->fr_literal, 3933 4, 3934 sym, 3935 0, 3936 0, 3937 BFD_RELOC_16_GOT_PCREL); 3938 3939} 3940 3941/* pseudo-op: 3942 behaviour: 3943 errors: 3944 warnings: */ 3945 3946static void 3947ppc_pe_comm (lcomm) 3948 int lcomm; 3949{ 3950 register char *name; 3951 register char c; 3952 register char *p; 3953 offsetT temp; 3954 register symbolS *symbolP; 3955 offsetT align; 3956 3957 name = input_line_pointer; 3958 c = get_symbol_end (); 3959 3960 /* just after name is now '\0'. */ 3961 p = input_line_pointer; 3962 *p = c; 3963 SKIP_WHITESPACE (); 3964 if (*input_line_pointer != ',') 3965 { 3966 as_bad (_("Expected comma after symbol-name: rest of line ignored.")); 3967 ignore_rest_of_line (); 3968 return; 3969 } 3970 3971 input_line_pointer++; /* skip ',' */ 3972 if ((temp = get_absolute_expression ()) < 0) 3973 { 3974 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp); 3975 ignore_rest_of_line (); 3976 return; 3977 } 3978 3979 if (! lcomm) 3980 { 3981 /* The third argument to .comm is the alignment. */ 3982 if (*input_line_pointer != ',') 3983 align = 3; 3984 else 3985 { 3986 ++input_line_pointer; 3987 align = get_absolute_expression (); 3988 if (align <= 0) 3989 { 3990 as_warn (_("ignoring bad alignment")); 3991 align = 3; 3992 } 3993 } 3994 } 3995 3996 *p = 0; 3997 symbolP = symbol_find_or_make (name); 3998 3999 *p = c; 4000 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP)) 4001 { 4002 as_bad (_("Ignoring attempt to re-define symbol `%s'."), 4003 S_GET_NAME (symbolP)); 4004 ignore_rest_of_line (); 4005 return; 4006 } 4007 4008 if (S_GET_VALUE (symbolP)) 4009 { 4010 if (S_GET_VALUE (symbolP) != (valueT) temp) 4011 as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."), 4012 S_GET_NAME (symbolP), 4013 (long) S_GET_VALUE (symbolP), 4014 (long) temp); 4015 } 4016 else 4017 { 4018 S_SET_VALUE (symbolP, (valueT) temp); 4019 S_SET_EXTERNAL (symbolP); 4020 } 4021 4022 demand_empty_rest_of_line (); 4023} 4024 4025/* 4026 * implement the .section pseudo op: 4027 * .section name {, "flags"} 4028 * ^ ^ 4029 * | +--- optional flags: 'b' for bss 4030 * | 'i' for info 4031 * +-- section name 'l' for lib 4032 * 'n' for noload 4033 * 'o' for over 4034 * 'w' for data 4035 * 'd' (apparently m88k for data) 4036 * 'x' for text 4037 * But if the argument is not a quoted string, treat it as a 4038 * subsegment number. 4039 * 4040 * FIXME: this is a copy of the section processing from obj-coff.c, with 4041 * additions/changes for the moto-pas assembler support. There are three 4042 * categories: 4043 * 4044 * FIXME: I just noticed this. This doesn't work at all really. It it 4045 * setting bits that bfd probably neither understands or uses. The 4046 * correct approach (?) will have to incorporate extra fields attached 4047 * to the section to hold the system specific stuff. (krk) 4048 * 4049 * Section Contents: 4050 * 'a' - unknown - referred to in documentation, but no definition supplied 4051 * 'c' - section has code 4052 * 'd' - section has initialized data 4053 * 'u' - section has uninitialized data 4054 * 'i' - section contains directives (info) 4055 * 'n' - section can be discarded 4056 * 'R' - remove section at link time 4057 * 4058 * Section Protection: 4059 * 'r' - section is readable 4060 * 'w' - section is writeable 4061 * 'x' - section is executable 4062 * 's' - section is sharable 4063 * 4064 * Section Alignment: 4065 * '0' - align to byte boundary 4066 * '1' - align to halfword undary 4067 * '2' - align to word boundary 4068 * '3' - align to doubleword boundary 4069 * '4' - align to quadword boundary 4070 * '5' - align to 32 byte boundary 4071 * '6' - align to 64 byte boundary 4072 * 4073 */ 4074 4075void 4076ppc_pe_section (ignore) 4077 int ignore ATTRIBUTE_UNUSED; 4078{ 4079 /* Strip out the section name. */ 4080 char *section_name; 4081 char c; 4082 char *name; 4083 unsigned int exp; 4084 flagword flags; 4085 segT sec; 4086 int align; 4087 4088 section_name = input_line_pointer; 4089 c = get_symbol_end (); 4090 4091 name = xmalloc (input_line_pointer - section_name + 1); 4092 strcpy (name, section_name); 4093 4094 *input_line_pointer = c; 4095 4096 SKIP_WHITESPACE (); 4097 4098 exp = 0; 4099 flags = SEC_NO_FLAGS; 4100 4101 if (strcmp (name, ".idata$2") == 0) 4102 { 4103 align = 0; 4104 } 4105 else if (strcmp (name, ".idata$3") == 0) 4106 { 4107 align = 0; 4108 } 4109 else if (strcmp (name, ".idata$4") == 0) 4110 { 4111 align = 2; 4112 } 4113 else if (strcmp (name, ".idata$5") == 0) 4114 { 4115 align = 2; 4116 } 4117 else if (strcmp (name, ".idata$6") == 0) 4118 { 4119 align = 1; 4120 } 4121 else 4122 /* Default alignment to 16 byte boundary. */ 4123 align = 4; 4124 4125 if (*input_line_pointer == ',') 4126 { 4127 ++input_line_pointer; 4128 SKIP_WHITESPACE (); 4129 if (*input_line_pointer != '"') 4130 exp = get_absolute_expression (); 4131 else 4132 { 4133 ++input_line_pointer; 4134 while (*input_line_pointer != '"' 4135 && ! is_end_of_line[(unsigned char) *input_line_pointer]) 4136 { 4137 switch (*input_line_pointer) 4138 { 4139 /* Section Contents */ 4140 case 'a': /* unknown */ 4141 as_bad (_("Unsupported section attribute -- 'a'")); 4142 break; 4143 case 'c': /* code section */ 4144 flags |= SEC_CODE; 4145 break; 4146 case 'd': /* section has initialized data */ 4147 flags |= SEC_DATA; 4148 break; 4149 case 'u': /* section has uninitialized data */ 4150 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA 4151 in winnt.h */ 4152 flags |= SEC_ROM; 4153 break; 4154 case 'i': /* section contains directives (info) */ 4155 /* FIXME: This is IMAGE_SCN_LNK_INFO 4156 in winnt.h */ 4157 flags |= SEC_HAS_CONTENTS; 4158 break; 4159 case 'n': /* section can be discarded */ 4160 flags &=~ SEC_LOAD; 4161 break; 4162 case 'R': /* Remove section at link time */ 4163 flags |= SEC_NEVER_LOAD; 4164 break; 4165 4166 /* Section Protection */ 4167 case 'r': /* section is readable */ 4168 flags |= IMAGE_SCN_MEM_READ; 4169 break; 4170 case 'w': /* section is writeable */ 4171 flags |= IMAGE_SCN_MEM_WRITE; 4172 break; 4173 case 'x': /* section is executable */ 4174 flags |= IMAGE_SCN_MEM_EXECUTE; 4175 break; 4176 case 's': /* section is sharable */ 4177 flags |= IMAGE_SCN_MEM_SHARED; 4178 break; 4179 4180 /* Section Alignment */ 4181 case '0': /* align to byte boundary */ 4182 flags |= IMAGE_SCN_ALIGN_1BYTES; 4183 align = 0; 4184 break; 4185 case '1': /* align to halfword boundary */ 4186 flags |= IMAGE_SCN_ALIGN_2BYTES; 4187 align = 1; 4188 break; 4189 case '2': /* align to word boundary */ 4190 flags |= IMAGE_SCN_ALIGN_4BYTES; 4191 align = 2; 4192 break; 4193 case '3': /* align to doubleword boundary */ 4194 flags |= IMAGE_SCN_ALIGN_8BYTES; 4195 align = 3; 4196 break; 4197 case '4': /* align to quadword boundary */ 4198 flags |= IMAGE_SCN_ALIGN_16BYTES; 4199 align = 4; 4200 break; 4201 case '5': /* align to 32 byte boundary */ 4202 flags |= IMAGE_SCN_ALIGN_32BYTES; 4203 align = 5; 4204 break; 4205 case '6': /* align to 64 byte boundary */ 4206 flags |= IMAGE_SCN_ALIGN_64BYTES; 4207 align = 6; 4208 break; 4209 4210 default: 4211 as_bad (_("unknown section attribute '%c'"), 4212 *input_line_pointer); 4213 break; 4214 } 4215 ++input_line_pointer; 4216 } 4217 if (*input_line_pointer == '"') 4218 ++input_line_pointer; 4219 } 4220 } 4221 4222 sec = subseg_new (name, (subsegT) exp); 4223 4224 ppc_set_current_section (sec); 4225 4226 if (flags != SEC_NO_FLAGS) 4227 { 4228 if (! bfd_set_section_flags (stdoutput, sec, flags)) 4229 as_bad (_("error setting flags for \"%s\": %s"), 4230 bfd_section_name (stdoutput, sec), 4231 bfd_errmsg (bfd_get_error ())); 4232 } 4233 4234 bfd_set_section_alignment (stdoutput, sec, align); 4235 4236} 4237 4238static void 4239ppc_pe_function (ignore) 4240 int ignore ATTRIBUTE_UNUSED; 4241{ 4242 char *name; 4243 char endc; 4244 symbolS *ext_sym; 4245 4246 name = input_line_pointer; 4247 endc = get_symbol_end (); 4248 4249 ext_sym = symbol_find_or_make (name); 4250 4251 *input_line_pointer = endc; 4252 4253 S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT); 4254 SF_SET_FUNCTION (ext_sym); 4255 SF_SET_PROCESS (ext_sym); 4256 coff_add_linesym (ext_sym); 4257 4258 demand_empty_rest_of_line (); 4259} 4260 4261static void 4262ppc_pe_tocd (ignore) 4263 int ignore ATTRIBUTE_UNUSED; 4264{ 4265 if (tocdata_section == 0) 4266 { 4267 tocdata_section = subseg_new (".tocd", 0); 4268 /* FIXME: section flags won't work. */ 4269 bfd_set_section_flags (stdoutput, tocdata_section, 4270 (SEC_ALLOC | SEC_LOAD | SEC_RELOC 4271 | SEC_READONLY | SEC_DATA)); 4272 4273 bfd_set_section_alignment (stdoutput, tocdata_section, 2); 4274 } 4275 else 4276 { 4277 rdata_section = subseg_new (".tocd", 0); 4278 } 4279 4280 ppc_set_current_section (tocdata_section); 4281 4282 demand_empty_rest_of_line (); 4283} 4284 4285/* Don't adjust TOC relocs to use the section symbol. */ 4286 4287int 4288ppc_pe_fix_adjustable (fix) 4289 fixS *fix; 4290{ 4291 return fix->fx_r_type != BFD_RELOC_PPC_TOC16; 4292} 4293 4294#endif 4295 4296#ifdef OBJ_XCOFF 4297 4298/* XCOFF specific symbol and file handling. */ 4299 4300/* Canonicalize the symbol name. We use the to force the suffix, if 4301 any, to use square brackets, and to be in upper case. */ 4302 4303char * 4304ppc_canonicalize_symbol_name (name) 4305 char *name; 4306{ 4307 char *s; 4308 4309 if (ppc_stab_symbol) 4310 return name; 4311 4312 for (s = name; *s != '\0' && *s != '{' && *s != '['; s++) 4313 ; 4314 if (*s != '\0') 4315 { 4316 char brac; 4317 4318 if (*s == '[') 4319 brac = ']'; 4320 else 4321 { 4322 *s = '['; 4323 brac = '}'; 4324 } 4325 4326 for (s++; *s != '\0' && *s != brac; s++) 4327 *s = TOUPPER (*s); 4328 4329 if (*s == '\0' || s[1] != '\0') 4330 as_bad (_("bad symbol suffix")); 4331 4332 *s = ']'; 4333 } 4334 4335 return name; 4336} 4337 4338/* Set the class of a symbol based on the suffix, if any. This is 4339 called whenever a new symbol is created. */ 4340 4341void 4342ppc_symbol_new_hook (sym) 4343 symbolS *sym; 4344{ 4345 struct ppc_tc_sy *tc; 4346 const char *s; 4347 4348 tc = symbol_get_tc (sym); 4349 tc->next = NULL; 4350 tc->output = 0; 4351 tc->class = -1; 4352 tc->real_name = NULL; 4353 tc->subseg = 0; 4354 tc->align = 0; 4355 tc->size = NULL; 4356 tc->within = NULL; 4357 4358 if (ppc_stab_symbol) 4359 return; 4360 4361 s = strchr (S_GET_NAME (sym), '['); 4362 if (s == (const char *) NULL) 4363 { 4364 /* There is no suffix. */ 4365 return; 4366 } 4367 4368 ++s; 4369 4370 switch (s[0]) 4371 { 4372 case 'B': 4373 if (strcmp (s, "BS]") == 0) 4374 tc->class = XMC_BS; 4375 break; 4376 case 'D': 4377 if (strcmp (s, "DB]") == 0) 4378 tc->class = XMC_DB; 4379 else if (strcmp (s, "DS]") == 0) 4380 tc->class = XMC_DS; 4381 break; 4382 case 'G': 4383 if (strcmp (s, "GL]") == 0) 4384 tc->class = XMC_GL; 4385 break; 4386 case 'P': 4387 if (strcmp (s, "PR]") == 0) 4388 tc->class = XMC_PR; 4389 break; 4390 case 'R': 4391 if (strcmp (s, "RO]") == 0) 4392 tc->class = XMC_RO; 4393 else if (strcmp (s, "RW]") == 0) 4394 tc->class = XMC_RW; 4395 break; 4396 case 'S': 4397 if (strcmp (s, "SV]") == 0) 4398 tc->class = XMC_SV; 4399 break; 4400 case 'T': 4401 if (strcmp (s, "TC]") == 0) 4402 tc->class = XMC_TC; 4403 else if (strcmp (s, "TI]") == 0) 4404 tc->class = XMC_TI; 4405 else if (strcmp (s, "TB]") == 0) 4406 tc->class = XMC_TB; 4407 else if (strcmp (s, "TC0]") == 0 || strcmp (s, "T0]") == 0) 4408 tc->class = XMC_TC0; 4409 break; 4410 case 'U': 4411 if (strcmp (s, "UA]") == 0) 4412 tc->class = XMC_UA; 4413 else if (strcmp (s, "UC]") == 0) 4414 tc->class = XMC_UC; 4415 break; 4416 case 'X': 4417 if (strcmp (s, "XO]") == 0) 4418 tc->class = XMC_XO; 4419 break; 4420 } 4421 4422 if (tc->class == -1) 4423 as_bad (_("Unrecognized symbol suffix")); 4424} 4425 4426/* Set the class of a label based on where it is defined. This 4427 handles symbols without suffixes. Also, move the symbol so that it 4428 follows the csect symbol. */ 4429 4430void 4431ppc_frob_label (sym) 4432 symbolS *sym; 4433{ 4434 if (ppc_current_csect != (symbolS *) NULL) 4435 { 4436 if (symbol_get_tc (sym)->class == -1) 4437 symbol_get_tc (sym)->class = symbol_get_tc (ppc_current_csect)->class; 4438 4439 symbol_remove (sym, &symbol_rootP, &symbol_lastP); 4440 symbol_append (sym, symbol_get_tc (ppc_current_csect)->within, 4441 &symbol_rootP, &symbol_lastP); 4442 symbol_get_tc (ppc_current_csect)->within = sym; 4443 } 4444} 4445 4446/* This variable is set by ppc_frob_symbol if any absolute symbols are 4447 seen. It tells ppc_adjust_symtab whether it needs to look through 4448 the symbols. */ 4449 4450static boolean ppc_saw_abs; 4451 4452/* Change the name of a symbol just before writing it out. Set the 4453 real name if the .rename pseudo-op was used. Otherwise, remove any 4454 class suffix. Return 1 if the symbol should not be included in the 4455 symbol table. */ 4456 4457int 4458ppc_frob_symbol (sym) 4459 symbolS *sym; 4460{ 4461 static symbolS *ppc_last_function; 4462 static symbolS *set_end; 4463 4464 /* Discard symbols that should not be included in the output symbol 4465 table. */ 4466 if (! symbol_used_in_reloc_p (sym) 4467 && ((symbol_get_bfdsym (sym)->flags & BSF_SECTION_SYM) != 0 4468 || (! S_IS_EXTERNAL (sym) 4469 && ! symbol_get_tc (sym)->output 4470 && S_GET_STORAGE_CLASS (sym) != C_FILE))) 4471 return 1; 4472 4473 if (symbol_get_tc (sym)->real_name != (char *) NULL) 4474 S_SET_NAME (sym, symbol_get_tc (sym)->real_name); 4475 else 4476 { 4477 const char *name; 4478 const char *s; 4479 4480 name = S_GET_NAME (sym); 4481 s = strchr (name, '['); 4482 if (s != (char *) NULL) 4483 { 4484 unsigned int len; 4485 char *snew; 4486 4487 len = s - name; 4488 snew = xmalloc (len + 1); 4489 memcpy (snew, name, len); 4490 snew[len] = '\0'; 4491 4492 S_SET_NAME (sym, snew); 4493 } 4494 } 4495 4496 if (set_end != (symbolS *) NULL) 4497 { 4498 SA_SET_SYM_ENDNDX (set_end, sym); 4499 set_end = NULL; 4500 } 4501 4502 if (SF_GET_FUNCTION (sym)) 4503 { 4504 if (ppc_last_function != (symbolS *) NULL) 4505 as_bad (_("two .function pseudo-ops with no intervening .ef")); 4506 ppc_last_function = sym; 4507 if (symbol_get_tc (sym)->size != (symbolS *) NULL) 4508 { 4509 resolve_symbol_value (symbol_get_tc (sym)->size); 4510 SA_SET_SYM_FSIZE (sym, 4511 (long) S_GET_VALUE (symbol_get_tc (sym)->size)); 4512 } 4513 } 4514 else if (S_GET_STORAGE_CLASS (sym) == C_FCN 4515 && strcmp (S_GET_NAME (sym), ".ef") == 0) 4516 { 4517 if (ppc_last_function == (symbolS *) NULL) 4518 as_bad (_(".ef with no preceding .function")); 4519 else 4520 { 4521 set_end = ppc_last_function; 4522 ppc_last_function = NULL; 4523 4524 /* We don't have a C_EFCN symbol, but we need to force the 4525 COFF backend to believe that it has seen one. */ 4526 coff_last_function = NULL; 4527 } 4528 } 4529 4530 if (! S_IS_EXTERNAL (sym) 4531 && (symbol_get_bfdsym (sym)->flags & BSF_SECTION_SYM) == 0 4532 && S_GET_STORAGE_CLASS (sym) != C_FILE 4533 && S_GET_STORAGE_CLASS (sym) != C_FCN 4534 && S_GET_STORAGE_CLASS (sym) != C_BLOCK 4535 && S_GET_STORAGE_CLASS (sym) != C_BSTAT 4536 && S_GET_STORAGE_CLASS (sym) != C_ESTAT 4537 && S_GET_STORAGE_CLASS (sym) != C_BINCL 4538 && S_GET_STORAGE_CLASS (sym) != C_EINCL 4539 && S_GET_SEGMENT (sym) != ppc_coff_debug_section) 4540 S_SET_STORAGE_CLASS (sym, C_HIDEXT); 4541 4542 if (S_GET_STORAGE_CLASS (sym) == C_EXT 4543 || S_GET_STORAGE_CLASS (sym) == C_HIDEXT) 4544 { 4545 int i; 4546 union internal_auxent *a; 4547 4548 /* Create a csect aux. */ 4549 i = S_GET_NUMBER_AUXILIARY (sym); 4550 S_SET_NUMBER_AUXILIARY (sym, i + 1); 4551 a = &coffsymbol (symbol_get_bfdsym (sym))->native[i + 1].u.auxent; 4552 if (symbol_get_tc (sym)->class == XMC_TC0) 4553 { 4554 /* This is the TOC table. */ 4555 know (strcmp (S_GET_NAME (sym), "TOC") == 0); 4556 a->x_csect.x_scnlen.l = 0; 4557 a->x_csect.x_smtyp = (2 << 3) | XTY_SD; 4558 } 4559 else if (symbol_get_tc (sym)->subseg != 0) 4560 { 4561 /* This is a csect symbol. x_scnlen is the size of the 4562 csect. */ 4563 if (symbol_get_tc (sym)->next == (symbolS *) NULL) 4564 a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput, 4565 S_GET_SEGMENT (sym)) 4566 - S_GET_VALUE (sym)); 4567 else 4568 { 4569 resolve_symbol_value (symbol_get_tc (sym)->next); 4570 a->x_csect.x_scnlen.l = (S_GET_VALUE (symbol_get_tc (sym)->next) 4571 - S_GET_VALUE (sym)); 4572 } 4573 a->x_csect.x_smtyp = (symbol_get_tc (sym)->align << 3) | XTY_SD; 4574 } 4575 else if (S_GET_SEGMENT (sym) == bss_section) 4576 { 4577 /* This is a common symbol. */ 4578 a->x_csect.x_scnlen.l = symbol_get_frag (sym)->fr_offset; 4579 a->x_csect.x_smtyp = (symbol_get_tc (sym)->align << 3) | XTY_CM; 4580 if (S_IS_EXTERNAL (sym)) 4581 symbol_get_tc (sym)->class = XMC_RW; 4582 else 4583 symbol_get_tc (sym)->class = XMC_BS; 4584 } 4585 else if (S_GET_SEGMENT (sym) == absolute_section) 4586 { 4587 /* This is an absolute symbol. The csect will be created by 4588 ppc_adjust_symtab. */ 4589 ppc_saw_abs = true; 4590 a->x_csect.x_smtyp = XTY_LD; 4591 if (symbol_get_tc (sym)->class == -1) 4592 symbol_get_tc (sym)->class = XMC_XO; 4593 } 4594 else if (! S_IS_DEFINED (sym)) 4595 { 4596 /* This is an external symbol. */ 4597 a->x_csect.x_scnlen.l = 0; 4598 a->x_csect.x_smtyp = XTY_ER; 4599 } 4600 else if (symbol_get_tc (sym)->class == XMC_TC) 4601 { 4602 symbolS *next; 4603 4604 /* This is a TOC definition. x_scnlen is the size of the 4605 TOC entry. */ 4606 next = symbol_next (sym); 4607 while (symbol_get_tc (next)->class == XMC_TC0) 4608 next = symbol_next (next); 4609 if (next == (symbolS *) NULL 4610 || symbol_get_tc (next)->class != XMC_TC) 4611 { 4612 if (ppc_after_toc_frag == (fragS *) NULL) 4613 a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput, 4614 data_section) 4615 - S_GET_VALUE (sym)); 4616 else 4617 a->x_csect.x_scnlen.l = (ppc_after_toc_frag->fr_address 4618 - S_GET_VALUE (sym)); 4619 } 4620 else 4621 { 4622 resolve_symbol_value (next); 4623 a->x_csect.x_scnlen.l = (S_GET_VALUE (next) 4624 - S_GET_VALUE (sym)); 4625 } 4626 a->x_csect.x_smtyp = (2 << 3) | XTY_SD; 4627 } 4628 else 4629 { 4630 symbolS *csect; 4631 4632 /* This is a normal symbol definition. x_scnlen is the 4633 symbol index of the containing csect. */ 4634 if (S_GET_SEGMENT (sym) == text_section) 4635 csect = ppc_text_csects; 4636 else if (S_GET_SEGMENT (sym) == data_section) 4637 csect = ppc_data_csects; 4638 else 4639 abort (); 4640 4641 /* Skip the initial dummy symbol. */ 4642 csect = symbol_get_tc (csect)->next; 4643 4644 if (csect == (symbolS *) NULL) 4645 { 4646 as_warn (_("warning: symbol %s has no csect"), S_GET_NAME (sym)); 4647 a->x_csect.x_scnlen.l = 0; 4648 } 4649 else 4650 { 4651 while (symbol_get_tc (csect)->next != (symbolS *) NULL) 4652 { 4653 resolve_symbol_value (symbol_get_tc (csect)->next); 4654 if (S_GET_VALUE (symbol_get_tc (csect)->next) 4655 > S_GET_VALUE (sym)) 4656 break; 4657 csect = symbol_get_tc (csect)->next; 4658 } 4659 4660 a->x_csect.x_scnlen.p = 4661 coffsymbol (symbol_get_bfdsym (csect))->native; 4662 coffsymbol (symbol_get_bfdsym (sym))->native[i + 1].fix_scnlen = 4663 1; 4664 } 4665 a->x_csect.x_smtyp = XTY_LD; 4666 } 4667 4668 a->x_csect.x_parmhash = 0; 4669 a->x_csect.x_snhash = 0; 4670 if (symbol_get_tc (sym)->class == -1) 4671 a->x_csect.x_smclas = XMC_PR; 4672 else 4673 a->x_csect.x_smclas = symbol_get_tc (sym)->class; 4674 a->x_csect.x_stab = 0; 4675 a->x_csect.x_snstab = 0; 4676 4677 /* Don't let the COFF backend resort these symbols. */ 4678 symbol_get_bfdsym (sym)->flags |= BSF_NOT_AT_END; 4679 } 4680 else if (S_GET_STORAGE_CLASS (sym) == C_BSTAT) 4681 { 4682 /* We want the value to be the symbol index of the referenced 4683 csect symbol. BFD will do that for us if we set the right 4684 flags. */ 4685 S_SET_VALUE (sym, 4686 ((valueT) 4687 coffsymbol (symbol_get_bfdsym 4688 (symbol_get_tc (sym)->within))->native)); 4689 coffsymbol (symbol_get_bfdsym (sym))->native->fix_value = 1; 4690 } 4691 else if (S_GET_STORAGE_CLASS (sym) == C_STSYM) 4692 { 4693 symbolS *block; 4694 symbolS *csect; 4695 4696 /* The value is the offset from the enclosing csect. */ 4697 block = symbol_get_tc (sym)->within; 4698 csect = symbol_get_tc (block)->within; 4699 resolve_symbol_value (csect); 4700 S_SET_VALUE (sym, S_GET_VALUE (sym) - S_GET_VALUE (csect)); 4701 } 4702 else if (S_GET_STORAGE_CLASS (sym) == C_BINCL 4703 || S_GET_STORAGE_CLASS (sym) == C_EINCL) 4704 { 4705 /* We want the value to be a file offset into the line numbers. 4706 BFD will do that for us if we set the right flags. We have 4707 already set the value correctly. */ 4708 coffsymbol (symbol_get_bfdsym (sym))->native->fix_line = 1; 4709 } 4710 4711 return 0; 4712} 4713 4714/* Adjust the symbol table. This creates csect symbols for all 4715 absolute symbols. */ 4716 4717void 4718ppc_adjust_symtab () 4719{ 4720 symbolS *sym; 4721 4722 if (! ppc_saw_abs) 4723 return; 4724 4725 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) 4726 { 4727 symbolS *csect; 4728 int i; 4729 union internal_auxent *a; 4730 4731 if (S_GET_SEGMENT (sym) != absolute_section) 4732 continue; 4733 4734 csect = symbol_create (".abs[XO]", absolute_section, 4735 S_GET_VALUE (sym), &zero_address_frag); 4736 symbol_get_bfdsym (csect)->value = S_GET_VALUE (sym); 4737 S_SET_STORAGE_CLASS (csect, C_HIDEXT); 4738 i = S_GET_NUMBER_AUXILIARY (csect); 4739 S_SET_NUMBER_AUXILIARY (csect, i + 1); 4740 a = &coffsymbol (symbol_get_bfdsym (csect))->native[i + 1].u.auxent; 4741 a->x_csect.x_scnlen.l = 0; 4742 a->x_csect.x_smtyp = XTY_SD; 4743 a->x_csect.x_parmhash = 0; 4744 a->x_csect.x_snhash = 0; 4745 a->x_csect.x_smclas = XMC_XO; 4746 a->x_csect.x_stab = 0; 4747 a->x_csect.x_snstab = 0; 4748 4749 symbol_insert (csect, sym, &symbol_rootP, &symbol_lastP); 4750 4751 i = S_GET_NUMBER_AUXILIARY (sym); 4752 a = &coffsymbol (symbol_get_bfdsym (sym))->native[i].u.auxent; 4753 a->x_csect.x_scnlen.p = coffsymbol (symbol_get_bfdsym (csect))->native; 4754 coffsymbol (symbol_get_bfdsym (sym))->native[i].fix_scnlen = 1; 4755 } 4756 4757 ppc_saw_abs = false; 4758} 4759 4760/* Set the VMA for a section. This is called on all the sections in 4761 turn. */ 4762 4763void 4764ppc_frob_section (sec) 4765 asection *sec; 4766{ 4767 static bfd_size_type vma = 0; 4768 4769 bfd_set_section_vma (stdoutput, sec, vma); 4770 vma += bfd_section_size (stdoutput, sec); 4771} 4772 4773#endif /* OBJ_XCOFF */ 4774 4775/* Turn a string in input_line_pointer into a floating point constant 4776 of type TYPE, and store the appropriate bytes in *LITP. The number 4777 of LITTLENUMS emitted is stored in *SIZEP. An error message is 4778 returned, or NULL on OK. */ 4779 4780char * 4781md_atof (type, litp, sizep) 4782 int type; 4783 char *litp; 4784 int *sizep; 4785{ 4786 int prec; 4787 LITTLENUM_TYPE words[4]; 4788 char *t; 4789 int i; 4790 4791 switch (type) 4792 { 4793 case 'f': 4794 prec = 2; 4795 break; 4796 4797 case 'd': 4798 prec = 4; 4799 break; 4800 4801 default: 4802 *sizep = 0; 4803 return _("bad call to md_atof"); 4804 } 4805 4806 t = atof_ieee (input_line_pointer, type, words); 4807 if (t) 4808 input_line_pointer = t; 4809 4810 *sizep = prec * 2; 4811 4812 if (target_big_endian) 4813 { 4814 for (i = 0; i < prec; i++) 4815 { 4816 md_number_to_chars (litp, (valueT) words[i], 2); 4817 litp += 2; 4818 } 4819 } 4820 else 4821 { 4822 for (i = prec - 1; i >= 0; i--) 4823 { 4824 md_number_to_chars (litp, (valueT) words[i], 2); 4825 litp += 2; 4826 } 4827 } 4828 4829 return NULL; 4830} 4831 4832/* Write a value out to the object file, using the appropriate 4833 endianness. */ 4834 4835void 4836md_number_to_chars (buf, val, n) 4837 char *buf; 4838 valueT val; 4839 int n; 4840{ 4841 if (target_big_endian) 4842 number_to_chars_bigendian (buf, val, n); 4843 else 4844 number_to_chars_littleendian (buf, val, n); 4845} 4846 4847/* Align a section (I don't know why this is machine dependent). */ 4848 4849valueT 4850md_section_align (seg, addr) 4851 asection *seg; 4852 valueT addr; 4853{ 4854 int align = bfd_get_section_alignment (stdoutput, seg); 4855 4856 return ((addr + (1 << align) - 1) & (-1 << align)); 4857} 4858 4859/* We don't have any form of relaxing. */ 4860 4861int 4862md_estimate_size_before_relax (fragp, seg) 4863 fragS *fragp ATTRIBUTE_UNUSED; 4864 asection *seg ATTRIBUTE_UNUSED; 4865{ 4866 abort (); 4867 return 0; 4868} 4869 4870/* Convert a machine dependent frag. We never generate these. */ 4871 4872void 4873md_convert_frag (abfd, sec, fragp) 4874 bfd *abfd ATTRIBUTE_UNUSED; 4875 asection *sec ATTRIBUTE_UNUSED; 4876 fragS *fragp ATTRIBUTE_UNUSED; 4877{ 4878 abort (); 4879} 4880 4881/* We have no need to default values of symbols. */ 4882 4883symbolS * 4884md_undefined_symbol (name) 4885 char *name ATTRIBUTE_UNUSED; 4886{ 4887 return 0; 4888} 4889 4890/* Functions concerning relocs. */ 4891 4892/* The location from which a PC relative jump should be calculated, 4893 given a PC relative reloc. */ 4894 4895long 4896md_pcrel_from_section (fixp, sec) 4897 fixS *fixp; 4898 segT sec ATTRIBUTE_UNUSED; 4899{ 4900 return fixp->fx_frag->fr_address + fixp->fx_where; 4901} 4902 4903#ifdef OBJ_XCOFF 4904 4905/* This is called to see whether a fixup should be adjusted to use a 4906 section symbol. We take the opportunity to change a fixup against 4907 a symbol in the TOC subsegment into a reloc against the 4908 corresponding .tc symbol. */ 4909 4910int 4911ppc_fix_adjustable (fix) 4912 fixS *fix; 4913{ 4914 valueT val; 4915 4916 resolve_symbol_value (fix->fx_addsy); 4917 val = S_GET_VALUE (fix->fx_addsy); 4918 if (ppc_toc_csect != (symbolS *) NULL 4919 && fix->fx_addsy != (symbolS *) NULL 4920 && fix->fx_addsy != ppc_toc_csect 4921 && S_GET_SEGMENT (fix->fx_addsy) == data_section 4922 && val >= ppc_toc_frag->fr_address 4923 && (ppc_after_toc_frag == (fragS *) NULL 4924 || val < ppc_after_toc_frag->fr_address)) 4925 { 4926 symbolS *sy; 4927 4928 for (sy = symbol_next (ppc_toc_csect); 4929 sy != (symbolS *) NULL; 4930 sy = symbol_next (sy)) 4931 { 4932 if (symbol_get_tc (sy)->class == XMC_TC0) 4933 continue; 4934 if (symbol_get_tc (sy)->class != XMC_TC) 4935 break; 4936 resolve_symbol_value (sy); 4937 if (val == S_GET_VALUE (sy)) 4938 { 4939 fix->fx_addsy = sy; 4940 fix->fx_addnumber = val - ppc_toc_frag->fr_address; 4941 return 0; 4942 } 4943 } 4944 4945 as_bad_where (fix->fx_file, fix->fx_line, 4946 _("symbol in .toc does not match any .tc")); 4947 } 4948 4949 /* Possibly adjust the reloc to be against the csect. */ 4950 if (fix->fx_addsy != (symbolS *) NULL 4951 && symbol_get_tc (fix->fx_addsy)->subseg == 0 4952 && symbol_get_tc (fix->fx_addsy)->class != XMC_TC0 4953 && symbol_get_tc (fix->fx_addsy)->class != XMC_TC 4954 && S_GET_SEGMENT (fix->fx_addsy) != bss_section 4955 /* Don't adjust if this is a reloc in the toc section. */ 4956 && (S_GET_SEGMENT (fix->fx_addsy) != data_section 4957 || ppc_toc_csect == NULL 4958 || val < ppc_toc_frag->fr_address 4959 || (ppc_after_toc_frag != NULL 4960 && val >= ppc_after_toc_frag->fr_address))) 4961 { 4962 symbolS *csect; 4963 4964 if (S_GET_SEGMENT (fix->fx_addsy) == text_section) 4965 csect = ppc_text_csects; 4966 else if (S_GET_SEGMENT (fix->fx_addsy) == data_section) 4967 csect = ppc_data_csects; 4968 else 4969 abort (); 4970 4971 /* Skip the initial dummy symbol. */ 4972 csect = symbol_get_tc (csect)->next; 4973 4974 if (csect != (symbolS *) NULL) 4975 { 4976 while (symbol_get_tc (csect)->next != (symbolS *) NULL 4977 && (symbol_get_frag (symbol_get_tc (csect)->next)->fr_address 4978 <= val)) 4979 { 4980 /* If the csect address equals the symbol value, then we 4981 have to look through the full symbol table to see 4982 whether this is the csect we want. Note that we will 4983 only get here if the csect has zero length. */ 4984 if ((symbol_get_frag (csect)->fr_address == val) 4985 && S_GET_VALUE (csect) == S_GET_VALUE (fix->fx_addsy)) 4986 { 4987 symbolS *scan; 4988 4989 for (scan = symbol_next (csect); 4990 scan != NULL; 4991 scan = symbol_next (scan)) 4992 { 4993 if (symbol_get_tc (scan)->subseg != 0) 4994 break; 4995 if (scan == fix->fx_addsy) 4996 break; 4997 } 4998 4999 /* If we found the symbol before the next csect 5000 symbol, then this is the csect we want. */ 5001 if (scan == fix->fx_addsy) 5002 break; 5003 } 5004 5005 csect = symbol_get_tc (csect)->next; 5006 } 5007 5008 fix->fx_offset += (S_GET_VALUE (fix->fx_addsy) 5009 - symbol_get_frag (csect)->fr_address); 5010 fix->fx_addsy = csect; 5011 } 5012 } 5013 5014 /* Adjust a reloc against a .lcomm symbol to be against the base 5015 .lcomm. */ 5016 if (fix->fx_addsy != (symbolS *) NULL 5017 && S_GET_SEGMENT (fix->fx_addsy) == bss_section 5018 && ! S_IS_EXTERNAL (fix->fx_addsy)) 5019 { 5020 resolve_symbol_value (symbol_get_frag (fix->fx_addsy)->fr_symbol); 5021 fix->fx_offset += 5022 (S_GET_VALUE (fix->fx_addsy) 5023 - S_GET_VALUE (symbol_get_frag (fix->fx_addsy)->fr_symbol)); 5024 fix->fx_addsy = symbol_get_frag (fix->fx_addsy)->fr_symbol; 5025 } 5026 5027 return 0; 5028} 5029 5030/* A reloc from one csect to another must be kept. The assembler 5031 will, of course, keep relocs between sections, and it will keep 5032 absolute relocs, but we need to force it to keep PC relative relocs 5033 between two csects in the same section. */ 5034 5035int 5036ppc_force_relocation (fix) 5037 fixS *fix; 5038{ 5039 /* At this point fix->fx_addsy should already have been converted to 5040 a csect symbol. If the csect does not include the fragment, then 5041 we need to force the relocation. */ 5042 if (fix->fx_pcrel 5043 && fix->fx_addsy != NULL 5044 && symbol_get_tc (fix->fx_addsy)->subseg != 0 5045 && ((symbol_get_frag (fix->fx_addsy)->fr_address 5046 > fix->fx_frag->fr_address) 5047 || (symbol_get_tc (fix->fx_addsy)->next != NULL 5048 && (symbol_get_frag (symbol_get_tc (fix->fx_addsy)->next)->fr_address 5049 <= fix->fx_frag->fr_address)))) 5050 return 1; 5051 5052 return 0; 5053} 5054 5055#endif /* OBJ_XCOFF */ 5056 5057#ifdef OBJ_ELF 5058int 5059ppc_fix_adjustable (fix) 5060 fixS *fix; 5061{ 5062 return (fix->fx_r_type != BFD_RELOC_16_GOTOFF 5063 && fix->fx_r_type != BFD_RELOC_LO16_GOTOFF 5064 && fix->fx_r_type != BFD_RELOC_HI16_GOTOFF 5065 && fix->fx_r_type != BFD_RELOC_HI16_S_GOTOFF 5066 && fix->fx_r_type != BFD_RELOC_GPREL16 5067 && fix->fx_r_type != BFD_RELOC_VTABLE_INHERIT 5068 && fix->fx_r_type != BFD_RELOC_VTABLE_ENTRY 5069 && ! S_IS_EXTERNAL (fix->fx_addsy) 5070 && ! S_IS_WEAK (fix->fx_addsy) 5071 && (fix->fx_pcrel 5072 || (fix->fx_subsy != NULL 5073 && (S_GET_SEGMENT (fix->fx_subsy) 5074 == S_GET_SEGMENT (fix->fx_addsy))) 5075 || S_IS_LOCAL (fix->fx_addsy))); 5076} 5077#endif 5078 5079/* Apply a fixup to the object code. This is called for all the 5080 fixups we generated by the call to fix_new_exp, above. In the call 5081 above we used a reloc code which was the largest legal reloc code 5082 plus the operand index. Here we undo that to recover the operand 5083 index. At this point all symbol values should be fully resolved, 5084 and we attempt to completely resolve the reloc. If we can not do 5085 that, we determine the correct reloc code and put it back in the 5086 fixup. */ 5087 5088void 5089md_apply_fix3 (fixP, valP, seg) 5090 fixS *fixP; 5091 valueT * valP; 5092 segT seg ATTRIBUTE_UNUSED; 5093{ 5094 valueT value = * valP; 5095 5096#ifdef OBJ_ELF 5097 if (fixP->fx_addsy != NULL) 5098 { 5099 /* `*valuep' may contain the value of the symbol on which the reloc 5100 will be based; we have to remove it. */ 5101 if (symbol_used_in_reloc_p (fixP->fx_addsy) 5102 && S_GET_SEGMENT (fixP->fx_addsy) != absolute_section 5103 && S_GET_SEGMENT (fixP->fx_addsy) != undefined_section 5104 && ! bfd_is_com_section (S_GET_SEGMENT (fixP->fx_addsy))) 5105 value -= S_GET_VALUE (fixP->fx_addsy); 5106 5107 /* FIXME: Why '+'? Better yet, what exactly is '*valuep' 5108 supposed to be? I think this is related to various similar 5109 FIXMEs in tc-i386.c and tc-sparc.c. */ 5110 if (fixP->fx_pcrel) 5111 value += fixP->fx_frag->fr_address + fixP->fx_where; 5112 } 5113 else 5114 fixP->fx_done = 1; 5115#else 5116 /* FIXME FIXME FIXME: The value we are passed in *valuep includes 5117 the symbol values. Since we are using BFD_ASSEMBLER, if we are 5118 doing this relocation the code in write.c is going to call 5119 bfd_install_relocation, which is also going to use the symbol 5120 value. That means that if the reloc is fully resolved we want to 5121 use *valuep since bfd_install_relocation is not being used. 5122 However, if the reloc is not fully resolved we do not want to use 5123 *valuep, and must use fx_offset instead. However, if the reloc 5124 is PC relative, we do want to use *valuep since it includes the 5125 result of md_pcrel_from. This is confusing. */ 5126 if (fixP->fx_addsy == (symbolS *) NULL) 5127 fixP->fx_done = 1; 5128 5129 else if (fixP->fx_pcrel) 5130 ; 5131 5132 else 5133 { 5134 value = fixP->fx_offset; 5135 if (fixP->fx_subsy != (symbolS *) NULL) 5136 { 5137 if (S_GET_SEGMENT (fixP->fx_subsy) == absolute_section) 5138 value -= S_GET_VALUE (fixP->fx_subsy); 5139 else 5140 { 5141 /* We can't actually support subtracting a symbol. */ 5142 as_bad_where (fixP->fx_file, fixP->fx_line, 5143 _("expression too complex")); 5144 } 5145 } 5146 } 5147#endif 5148 5149 if ((int) fixP->fx_r_type >= (int) BFD_RELOC_UNUSED) 5150 { 5151 int opindex; 5152 const struct powerpc_operand *operand; 5153 char *where; 5154 unsigned long insn; 5155 5156 opindex = (int) fixP->fx_r_type - (int) BFD_RELOC_UNUSED; 5157 5158 operand = &powerpc_operands[opindex]; 5159 5160#ifdef OBJ_XCOFF 5161 /* An instruction like `lwz 9,sym(30)' when `sym' is not a TOC symbol 5162 does not generate a reloc. It uses the offset of `sym' within its 5163 csect. Other usages, such as `.long sym', generate relocs. This 5164 is the documented behaviour of non-TOC symbols. */ 5165 if ((operand->flags & PPC_OPERAND_PARENS) != 0 5166 && operand->bits == 16 5167 && operand->shift == 0 5168 && operand->insert == NULL 5169 && fixP->fx_addsy != NULL 5170 && symbol_get_tc (fixP->fx_addsy)->subseg != 0 5171 && symbol_get_tc (fixP->fx_addsy)->class != XMC_TC 5172 && symbol_get_tc (fixP->fx_addsy)->class != XMC_TC0 5173 && S_GET_SEGMENT (fixP->fx_addsy) != bss_section) 5174 { 5175 value = fixP->fx_offset; 5176 fixP->fx_done = 1; 5177 } 5178#endif 5179 5180 /* Fetch the instruction, insert the fully resolved operand 5181 value, and stuff the instruction back again. */ 5182 where = fixP->fx_frag->fr_literal + fixP->fx_where; 5183 if (target_big_endian) 5184 insn = bfd_getb32 ((unsigned char *) where); 5185 else 5186 insn = bfd_getl32 ((unsigned char *) where); 5187 insn = ppc_insert_operand (insn, operand, (offsetT) value, 5188 fixP->fx_file, fixP->fx_line); 5189 if (target_big_endian) 5190 bfd_putb32 ((bfd_vma) insn, (unsigned char *) where); 5191 else 5192 bfd_putl32 ((bfd_vma) insn, (unsigned char *) where); 5193 5194 if (fixP->fx_done) 5195 /* Nothing else to do here. */ 5196 return; 5197 5198 assert (fixP->fx_addsy != NULL); 5199 5200 /* Determine a BFD reloc value based on the operand information. 5201 We are only prepared to turn a few of the operands into 5202 relocs. */ 5203 if ((operand->flags & PPC_OPERAND_RELATIVE) != 0 5204 && operand->bits == 26 5205 && operand->shift == 0) 5206 fixP->fx_r_type = BFD_RELOC_PPC_B26; 5207 else if ((operand->flags & PPC_OPERAND_RELATIVE) != 0 5208 && operand->bits == 16 5209 && operand->shift == 0) 5210 fixP->fx_r_type = BFD_RELOC_PPC_B16; 5211 else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0 5212 && operand->bits == 26 5213 && operand->shift == 0) 5214 fixP->fx_r_type = BFD_RELOC_PPC_BA26; 5215 else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0 5216 && operand->bits == 16 5217 && operand->shift == 0) 5218 fixP->fx_r_type = BFD_RELOC_PPC_BA16; 5219#if defined (OBJ_XCOFF) || defined (OBJ_ELF) 5220 else if ((operand->flags & PPC_OPERAND_PARENS) != 0 5221 && operand->bits == 16 5222 && operand->shift == 0 5223 && ppc_is_toc_sym (fixP->fx_addsy)) 5224 { 5225 fixP->fx_r_type = BFD_RELOC_PPC_TOC16; 5226#ifdef OBJ_ELF 5227 if (BFD_DEFAULT_TARGET_SIZE == 64 5228 && ppc_size == PPC_OPCODE_64 5229 && (operand->flags & PPC_OPERAND_DS) != 0) 5230 fixP->fx_r_type = BFD_RELOC_PPC64_TOC16_DS; 5231#endif 5232 fixP->fx_size = 2; 5233 if (target_big_endian) 5234 fixP->fx_where += 2; 5235 } 5236#endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */ 5237 else 5238 { 5239 char *sfile; 5240 unsigned int sline; 5241 5242 /* Use expr_symbol_where to see if this is an expression 5243 symbol. */ 5244 if (expr_symbol_where (fixP->fx_addsy, &sfile, &sline)) 5245 as_bad_where (fixP->fx_file, fixP->fx_line, 5246 _("unresolved expression that must be resolved")); 5247 else 5248 as_bad_where (fixP->fx_file, fixP->fx_line, 5249 _("unsupported relocation against %s"), 5250 S_GET_NAME (fixP->fx_addsy)); 5251 fixP->fx_done = 1; 5252 return; 5253 } 5254 } 5255 else 5256 { 5257#ifdef OBJ_ELF 5258 ppc_elf_validate_fix (fixP, seg); 5259#endif 5260 switch (fixP->fx_r_type) 5261 { 5262 case BFD_RELOC_CTOR: 5263 if (BFD_DEFAULT_TARGET_SIZE == 64 && ppc_size == PPC_OPCODE_64) 5264 goto ctor64; 5265 /* fall through */ 5266 5267 case BFD_RELOC_32: 5268 if (fixP->fx_pcrel) 5269 fixP->fx_r_type = BFD_RELOC_32_PCREL; 5270 /* fall through */ 5271 5272 case BFD_RELOC_RVA: 5273 case BFD_RELOC_32_PCREL: 5274 case BFD_RELOC_32_BASEREL: 5275 case BFD_RELOC_PPC_EMB_NADDR32: 5276 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, 5277 value, 4); 5278 break; 5279 5280 case BFD_RELOC_64: 5281 ctor64: 5282 if (fixP->fx_pcrel) 5283 fixP->fx_r_type = BFD_RELOC_64_PCREL; 5284 /* fall through */ 5285 5286 case BFD_RELOC_64_PCREL: 5287 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, 5288 value, 8); 5289 break; 5290 5291 case BFD_RELOC_LO16: 5292 case BFD_RELOC_16: 5293 case BFD_RELOC_GPREL16: 5294 case BFD_RELOC_16_GOT_PCREL: 5295 case BFD_RELOC_16_GOTOFF: 5296 case BFD_RELOC_LO16_GOTOFF: 5297 case BFD_RELOC_HI16_GOTOFF: 5298 case BFD_RELOC_HI16_S_GOTOFF: 5299 case BFD_RELOC_LO16_BASEREL: 5300 case BFD_RELOC_HI16_BASEREL: 5301 case BFD_RELOC_HI16_S_BASEREL: 5302 case BFD_RELOC_PPC_EMB_NADDR16: 5303 case BFD_RELOC_PPC_EMB_NADDR16_LO: 5304 case BFD_RELOC_PPC_EMB_NADDR16_HI: 5305 case BFD_RELOC_PPC_EMB_NADDR16_HA: 5306 case BFD_RELOC_PPC_EMB_SDAI16: 5307 case BFD_RELOC_PPC_EMB_SDA2REL: 5308 case BFD_RELOC_PPC_EMB_SDA2I16: 5309 case BFD_RELOC_PPC_EMB_RELSEC16: 5310 case BFD_RELOC_PPC_EMB_RELST_LO: 5311 case BFD_RELOC_PPC_EMB_RELST_HI: 5312 case BFD_RELOC_PPC_EMB_RELST_HA: 5313 case BFD_RELOC_PPC_EMB_RELSDA: 5314 case BFD_RELOC_PPC_TOC16: 5315#ifdef OBJ_ELF 5316#if BFD_DEFAULT_TARGET_SIZE == 64 5317 case BFD_RELOC_PPC64_TOC16_LO: 5318 case BFD_RELOC_PPC64_TOC16_HI: 5319 case BFD_RELOC_PPC64_TOC16_HA: 5320#endif 5321#endif 5322 if (fixP->fx_pcrel) 5323 { 5324 if (fixP->fx_addsy != NULL) 5325 as_bad_where (fixP->fx_file, fixP->fx_line, 5326 _("cannot emit PC relative %s relocation against %s"), 5327 bfd_get_reloc_code_name (fixP->fx_r_type), 5328 S_GET_NAME (fixP->fx_addsy)); 5329 else 5330 as_bad_where (fixP->fx_file, fixP->fx_line, 5331 _("cannot emit PC relative %s relocation"), 5332 bfd_get_reloc_code_name (fixP->fx_r_type)); 5333 } 5334 5335 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, 5336 value, 2); 5337 break; 5338 5339 /* This case happens when you write, for example, 5340 lis %r3,(L1-L2)@ha 5341 where L1 and L2 are defined later. */ 5342 case BFD_RELOC_HI16: 5343 if (fixP->fx_pcrel) 5344 abort (); 5345 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, 5346 PPC_HI (value), 2); 5347 break; 5348 5349 case BFD_RELOC_HI16_S: 5350 if (fixP->fx_pcrel) 5351 abort (); 5352 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, 5353 PPC_HA (value), 2); 5354 break; 5355 5356#ifdef OBJ_ELF 5357#if BFD_DEFAULT_TARGET_SIZE == 64 5358 case BFD_RELOC_PPC64_HIGHER: 5359 if (fixP->fx_pcrel) 5360 abort (); 5361 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, 5362 PPC_HIGHER (value), 2); 5363 break; 5364 5365 case BFD_RELOC_PPC64_HIGHER_S: 5366 if (fixP->fx_pcrel) 5367 abort (); 5368 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, 5369 PPC_HIGHERA (value), 2); 5370 break; 5371 5372 case BFD_RELOC_PPC64_HIGHEST: 5373 if (fixP->fx_pcrel) 5374 abort (); 5375 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, 5376 PPC_HIGHEST (value), 2); 5377 break; 5378 5379 case BFD_RELOC_PPC64_HIGHEST_S: 5380 if (fixP->fx_pcrel) 5381 abort (); 5382 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, 5383 PPC_HIGHESTA (value), 2); 5384 break; 5385 5386 case BFD_RELOC_PPC64_ADDR16_DS: 5387 case BFD_RELOC_PPC64_ADDR16_LO_DS: 5388 case BFD_RELOC_PPC64_GOT16_DS: 5389 case BFD_RELOC_PPC64_GOT16_LO_DS: 5390 case BFD_RELOC_PPC64_PLT16_LO_DS: 5391 case BFD_RELOC_PPC64_SECTOFF_DS: 5392 case BFD_RELOC_PPC64_SECTOFF_LO_DS: 5393 case BFD_RELOC_PPC64_TOC16_DS: 5394 case BFD_RELOC_PPC64_TOC16_LO_DS: 5395 case BFD_RELOC_PPC64_PLTGOT16_DS: 5396 case BFD_RELOC_PPC64_PLTGOT16_LO_DS: 5397 if (fixP->fx_pcrel) 5398 abort (); 5399 { 5400 unsigned char *where = fixP->fx_frag->fr_literal + fixP->fx_where; 5401 unsigned long val; 5402 5403 if (target_big_endian) 5404 val = bfd_getb16 (where); 5405 else 5406 val = bfd_getl16 (where); 5407 val |= (value & 0xfffc); 5408 if (target_big_endian) 5409 bfd_putb16 ((bfd_vma) val, where); 5410 else 5411 bfd_putl16 ((bfd_vma) val, where); 5412 } 5413 break; 5414#endif 5415#endif 5416 /* Because SDA21 modifies the register field, the size is set to 4 5417 bytes, rather than 2, so offset it here appropriately. */ 5418 case BFD_RELOC_PPC_EMB_SDA21: 5419 if (fixP->fx_pcrel) 5420 abort (); 5421 5422 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where 5423 + ((target_big_endian) ? 2 : 0), 5424 value, 2); 5425 break; 5426 5427 case BFD_RELOC_8: 5428 if (fixP->fx_pcrel) 5429 abort (); 5430 5431 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, 5432 value, 1); 5433 break; 5434 5435 case BFD_RELOC_24_PLT_PCREL: 5436 case BFD_RELOC_PPC_LOCAL24PC: 5437 if (!fixP->fx_pcrel && !fixP->fx_done) 5438 abort (); 5439 5440 if (fixP->fx_done) 5441 { 5442 char *where; 5443 unsigned long insn; 5444 5445 /* Fetch the instruction, insert the fully resolved operand 5446 value, and stuff the instruction back again. */ 5447 where = fixP->fx_frag->fr_literal + fixP->fx_where; 5448 if (target_big_endian) 5449 insn = bfd_getb32 ((unsigned char *) where); 5450 else 5451 insn = bfd_getl32 ((unsigned char *) where); 5452 if ((value & 3) != 0) 5453 as_bad_where (fixP->fx_file, fixP->fx_line, 5454 _("must branch to an address a multiple of 4")); 5455 if ((offsetT) value < -0x40000000 5456 || (offsetT) value >= 0x40000000) 5457 as_bad_where (fixP->fx_file, fixP->fx_line, 5458 _("@local or @plt branch destination is too far away, %ld bytes"), 5459 (long) value); 5460 insn = insn | (value & 0x03fffffc); 5461 if (target_big_endian) 5462 bfd_putb32 ((bfd_vma) insn, (unsigned char *) where); 5463 else 5464 bfd_putl32 ((bfd_vma) insn, (unsigned char *) where); 5465 } 5466 break; 5467 5468 case BFD_RELOC_VTABLE_INHERIT: 5469 fixP->fx_done = 0; 5470 if (fixP->fx_addsy 5471 && !S_IS_DEFINED (fixP->fx_addsy) 5472 && !S_IS_WEAK (fixP->fx_addsy)) 5473 S_SET_WEAK (fixP->fx_addsy); 5474 break; 5475 5476 case BFD_RELOC_VTABLE_ENTRY: 5477 fixP->fx_done = 0; 5478 break; 5479 5480#ifdef OBJ_ELF 5481#if BFD_DEFAULT_TARGET_SIZE == 64 5482 /* Generated by reference to `sym@tocbase'. The sym is 5483 ignored by the linker. */ 5484 case BFD_RELOC_PPC64_TOC: 5485 fixP->fx_done = 0; 5486 break; 5487#endif 5488#endif 5489 default: 5490 fprintf (stderr, 5491 _("Gas failure, reloc value %d\n"), fixP->fx_r_type); 5492 fflush (stderr); 5493 abort (); 5494 } 5495 } 5496 5497#ifdef OBJ_ELF 5498 fixP->fx_addnumber = value; 5499#else 5500 if (fixP->fx_r_type != BFD_RELOC_PPC_TOC16) 5501 fixP->fx_addnumber = 0; 5502 else 5503 { 5504#ifdef TE_PE 5505 fixP->fx_addnumber = 0; 5506#else 5507 /* We want to use the offset within the data segment of the 5508 symbol, not the actual VMA of the symbol. */ 5509 fixP->fx_addnumber = 5510 - bfd_get_section_vma (stdoutput, S_GET_SEGMENT (fixP->fx_addsy)); 5511#endif 5512 } 5513#endif 5514} 5515 5516/* Generate a reloc for a fixup. */ 5517 5518arelent * 5519tc_gen_reloc (seg, fixp) 5520 asection *seg ATTRIBUTE_UNUSED; 5521 fixS *fixp; 5522{ 5523 arelent *reloc; 5524 5525 reloc = (arelent *) xmalloc (sizeof (arelent)); 5526 5527 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); 5528 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); 5529 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; 5530 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type); 5531 if (reloc->howto == (reloc_howto_type *) NULL) 5532 { 5533 as_bad_where (fixp->fx_file, fixp->fx_line, 5534 _("reloc %d not supported by object file format"), 5535 (int) fixp->fx_r_type); 5536 return NULL; 5537 } 5538 reloc->addend = fixp->fx_addnumber; 5539 5540 return reloc; 5541} 5542