aboutsummaryrefslogtreecommitdiff
path: root/binutils/makefile.vms
blob: 0630b4b290e1e466fe5efbec491cca8e64235dea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#
# Makefile for binutils under openVMS (Alpha and Itanium)
#
# For use with gnu-make for vms
#
# Created by Klaus Kaempf, kkaempf@rmi.de
#
#   Copyright (C) 2012-2014 Free Software Foundation, Inc.
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING3.  If not see
# <http://www.gnu.org/licenses/>.
#

DEFS=/define=("OBJDUMP_PRIVATE_VECTORS=")
OPT=/noopt/debug
CFLAGS=$(OPT)/include=([],"../include",[-.bfd])$(DEFS)\
 /name=(as_is,shortened)\
 /prefix=(all,except=("getopt","optarg","optopt","optind","opterr"))\
 /warns=(info=(ptrmismatch,shiftcount))

LIBBFD = [-.bfd]libbfd.olb/lib
LIBBFD_DEP = [-.bfd]libbfd.olb
LIBIBERTY_DEP = [-.libiberty]libiberty.olb
LIBIBERTY = [-.libiberty]libiberty.olb/lib
OPCODES_DEP = [-.opcodes]libopcodes.olb
OPCODES = [-.opcodes]libopcodes.olb/lib

DEBUG_OBJS = rddbg.obj,debug.obj,stabs.obj,ieee.obj,rdcoff.obj,dwarf.obj,\
  elfcomm.obj

BULIBS = bucomm.obj,version.obj,filemode.obj

ADDL_DEPS = $(BULIBS),$(LIBBFD_DEP),$(LIBIBERTY_DEP)
ADDL_LIBS = $(BULIBS),$(LIBBFD),$(LIBIBERTY)

SIZEOBJS = $(ADDL_DEPS),size.obj

STRINGSOBJS = $(ADDL_DEPS),strings.obj

NMOBJS = $(ADDL_DEPS),nm.obj

ADDR2LINEOBJS = $(ADDL_DEPS),addr2line.obj

OBJDUMPOBJS = objdump.obj,prdbg.obj,$(DEBUG_OBJS),$(ADDL_DEPS),$(OPCODES_DEP)

READELFOBJS = readelf.obj,dwarf.obj,unwind-ia64.obj,$(ADDL_DEPS)

all: config.h size.exe strings.exe objdump.exe nm.exe addr2line.exe

size.exe: $(SIZEOBJS)
	link/exe=$@ size.obj,$(ADDL_LIBS)

strings.exe: $(STRINGSOBJS)
	link/exe=$@ strings.obj,$(ADDL_LIBS)

nm.exe: $(NMOBJS)
	link/exe=$@ nm.obj,$(ADDL_LIBS)

addr2line.exe: $(ADDR2LINEOBJS)
	link/exe=$@ addr2line.obj,$(ADDL_LIBS)

objdump.exe: $(OBJDUMPOBJS)
	link/exe=$@ objdump.obj,prdbg.obj,$(DEBUG_OBJS),$(ADDL_LIBS),$(OPCODES)

readelf.exe: $(READELFOBJS)
	link/exe=$@ readelf.obj,dwarf.obj,unwind-ia64.obj,$(ADDL_LIBS)

config.h:
	$$ @configure
	$(MAKE) -f makefile.vms "CC=$(CC)"

clean:
	$$ purge
	$(RM) *.obj;
	$(RM) *.exe;

distclean: clean
	$(RM) config.h;
	$(RM) makefile.vms;
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550
/* D30V-specific support for 32-bit ELF
   Copyright (C) 1997-2014 Free Software Foundation, Inc.
   Contributed by Martin Hunt (hunt@cygnus.com).

   This file is part of BFD, the Binary File Descriptor library.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
   MA 02110-1301, USA.  */

#include "sysdep.h"
#include "bfd.h"
#include "libbfd.h"
#include "elf-bfd.h"
#include "elf/d30v.h"

#define MAX32 ((bfd_signed_vma) 0x7fffffff)
#define MIN32 (- MAX32 - 1)

static bfd_reloc_status_type
bfd_elf_d30v_reloc (bfd *abfd,
		    arelent *reloc_entry,
		    asymbol *symbol,
		    void * data,
		    asection *input_section,
		    bfd *output_bfd,
		    char **error_message)
{
  bfd_signed_vma relocation;
  bfd_vma in1, in2, num;
  bfd_vma tmp_addr = 0;
  bfd_reloc_status_type r;
  asection *reloc_target_output_section;
  bfd_size_type addr = reloc_entry->address;
  bfd_reloc_status_type flag = bfd_reloc_ok;
  bfd_vma output_base = 0;
  reloc_howto_type *howto = reloc_entry->howto;
  int make_absolute = 0;

  if (output_bfd != NULL)
    {
      /* Partial linking -- do nothing.  */
      reloc_entry->address += input_section->output_offset;
      return bfd_reloc_ok;
    }

  r = bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
                             input_section, output_bfd, error_message);
  if (r != bfd_reloc_continue)
    return r;

  /* A hacked-up version of bfd_perform_reloc() follows.  */
 if (bfd_is_und_section (symbol->section)
      && (symbol->flags & BSF_WEAK) == 0
      && output_bfd == NULL)
    flag = bfd_reloc_undefined;

  /* Is the address of the relocation really within the section?  */
  if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
    return bfd_reloc_outofrange;

  /* Work out which section the relocation is targeted at and the
     initial relocation command value.  */

  /* Get symbol value.  (Common symbols are special.)  */
  if (bfd_is_com_section (symbol->section))
    relocation = 0;
  else
    relocation = symbol->value;

  reloc_target_output_section = symbol->section->output_section;

  /* Convert input-section-relative symbol value to absolute.  */
  output_base = reloc_target_output_section->vma;
  relocation += output_base + symbol->section->output_offset;

  /* Add in supplied addend.  */
  relocation += reloc_entry->addend;

  /* Here the variable relocation holds the final address of the
     symbol we are relocating against, plus any addend.  */
  if (howto->pc_relative)
    {
      tmp_addr = input_section->output_section->vma
	+ input_section->output_offset
	+ reloc_entry->address;
      relocation -= tmp_addr;
    }

  in1 = bfd_get_32 (abfd, (bfd_byte *) data + addr);
  in2 = bfd_get_32 (abfd, (bfd_byte *) data + addr + 4);

  /* Extract the addend.  */
  num = ((in2 & 0x3FFFF)
	 | ((in2 & 0xFF00000) >> 2)
	 | ((in1 & 0x3F) << 26));
  in1 &= 0xFFFFFFC0;
  in2 = 0x80000000;

  relocation += num;

  if (howto->pc_relative && howto->bitsize == 32)
    {
      /* The D30V has a PC that doesn't wrap and PC-relative jumps are
	 signed, so a PC-relative jump can't be more than +/- 2^31 bytes.
	 If one exceeds this, change it to an absolute jump.  */
      if (relocation > MAX32 || relocation < MIN32)
	{
	  relocation = (relocation + tmp_addr) & 0xffffffff;
	  make_absolute = 1;
	}
    }

  in1 |= (relocation >> 26) & 0x3F;		/* Top 6 bits.  */
  in2 |= ((relocation & 0x03FC0000) << 2);  	/* Next 8 bits.  */
  in2 |= relocation & 0x0003FFFF;		/* Bottom 18 bits.  */

  /* Change a PC-relative instruction to its
     absolute equivalent with this simple hack.  */
  if (make_absolute)
    in1 |= 0x00100000;

  bfd_put_32 (abfd, in1, (bfd_byte *) data + addr);
  bfd_put_32 (abfd, in2, (bfd_byte *) data + addr + 4);

  return flag;
}

static bfd_reloc_status_type
bfd_elf_d30v_reloc_21 (bfd *abfd,
		       arelent *reloc_entry,
		       asymbol *symbol,
		       void * data,
		       asection *input_section,
		       bfd *output_bfd,
		       char **error_message)
{
  bfd_vma relocation;
  bfd_vma in1, num;
  bfd_reloc_status_type r;
  asection *reloc_target_output_section;
  bfd_size_type addr = reloc_entry->address;
  bfd_reloc_status_type flag = bfd_reloc_ok;
  bfd_vma output_base = 0;
  reloc_howto_type *howto = reloc_entry->howto;
  int mask, max;

  if (output_bfd != NULL)
    {
      /* Partial linking -- do nothing.  */
      reloc_entry->address += input_section->output_offset;
      return bfd_reloc_ok;
    }

  r = bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
                             input_section, output_bfd, error_message);
  if (r != bfd_reloc_continue)
    return r;

  /* A hacked-up version of bfd_perform_reloc() follows.  */
  if (bfd_is_und_section (symbol->section)
      && (symbol->flags & BSF_WEAK) == 0
      && output_bfd == NULL)
    flag = bfd_reloc_undefined;

  /* Is the address of the relocation really within the section?  */
  if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
    return bfd_reloc_outofrange;

  /* Work out which section the relocation is targeted at and the
     initial relocation command value.  */

  /* Get symbol value.  (Common symbols are special.)  */
  if (bfd_is_com_section (symbol->section))
    relocation = 0;
  else
    relocation = symbol->value;

  reloc_target_output_section = symbol->section->output_section;

  /* Convert input-section-relative symbol value to absolute.  */
  output_base = reloc_target_output_section->vma;
  relocation += output_base + symbol->section->output_offset;

  /* Add in supplied addend.  */
  relocation += reloc_entry->addend;

  /* Here the variable relocation holds the final address of the
     symbol we are relocating against, plus any addend.  */

  if (howto->pc_relative)
    {
      relocation -= (input_section->output_section->vma
		     + input_section->output_offset);
      if (howto->pcrel_offset)
	relocation -= reloc_entry->address;
    }

  in1 = bfd_get_32 (abfd, (bfd_byte *) data + addr);

  mask =  (1 << howto->bitsize) - 1;
  if (howto->bitsize == 6)
    mask <<= 12;
  max = (1 << (howto->bitsize + 2)) - 1;

  /* Extract the addend.  */
  num = in1 & mask;  /* 18 bits.  */
  if (howto->bitsize == 6)
    num >>= 12;
  num <<= 3; /* shift left 3.  */
  in1 &= ~mask;  /* Mask out addend.  */

  relocation += num;
  if (howto->type == R_D30V_21_PCREL_R
      || howto->type == R_D30V_15_PCREL_R
      || howto->type == R_D30V_9_PCREL_R)
    relocation += 4;

  if ((int) relocation < 0)
    {
      if (~ (int) relocation > max)
	flag = bfd_reloc_overflow;
    }
  else
    {
      if ((int) relocation > max)
	flag = bfd_reloc_overflow;
    }

  relocation >>= 3;
  if (howto->bitsize == 6)
    in1 |= ((relocation & (mask >> 12)) << 12);
  else
    in1 |= relocation & mask;

  bfd_put_32 (abfd, in1, (bfd_byte *) data + addr);

  return flag;
}

static reloc_howto_type elf_d30v_howto_table[] =
{
  /* This reloc does nothing.  */
  HOWTO (R_D30V_NONE,		/* Type.  */
	 0,			/* Rightshift.  */
	 2,			/* Size (0 = byte, 1 = short, 2 = long).  */
	 32,			/* Bitsize.  */
	 FALSE,			/* PC_relative.  */
	 0,			/* Bitpos.  */
	 complain_overflow_bitfield, /* Complain_on_overflow.  */
	 bfd_elf_generic_reloc,	/* Special_function.  */
	 "R_D30V_NONE",		/* Name.  */
	 FALSE,			/* Partial_inplace.  */
	 0,			/* Src_mask.  */
	 0,			/* Dst_mask.  */
	 FALSE),		/* PCrel_offset.  */

  /* A 6 bit absolute relocation.  */
  HOWTO (R_D30V_6,		/* Type.  */
	 0,			/* Rightshift.  */
	 2,			/* Size (0 = byte, 1 = short, 2 = long).  */
	 6,			/* Bitsize.  */
	 FALSE,			/* PC_relative.  */
	 0,			/* Bitpos.  */
	 complain_overflow_bitfield, /* Complain_on_overflow.  */
	 bfd_elf_generic_reloc,	/* Special_function.  */
	 "R_D30V_6",		/* Name.  */
	 FALSE,			/* Partial_inplace.  */
	 0x3f,			/* Src_mask.  */
	 0x3f,			/* Dst_mask.  */
	 FALSE),		/* PCrel_offset.  */

  /* A relative 9 bit relocation, right shifted by 3.  */
  HOWTO (R_D30V_9_PCREL,	/* Type.  */
	 3,			/* Rightshift.  */
	 2,			/* Size (0 = byte, 1 = short, 2 = long).  */