// File: /workspace/github_c_makefile_star2_O0/deplinenoise[P]vlink/targets.c
// Function: calc_relocs
void calc_relocs(struct GlobalVars *gv,struct LinkedSection *ls)
/* calculate and insert all relocations of a section */
{
  const char *fn = "calc_reloc(): ";
  struct Reloc *r;

  if (ls == NULL)
    return;

  for (r=(struct Reloc *)ls->relocs.first; r->n.next!=NULL;
       r=(struct Reloc *)r->n.next) {
    lword s,a,p,val;

    if (r->relocsect.lnk == NULL) {
      if (r->flags & RELF_DYNLINK)
        continue;  /* NULL, because it was resolved by a shared object */
      else
        ierror("calc_relocs: Reloc type %d (%s) at %s+0x%lx (addend 0x%llx)"
               " is missing a relocsect.lnk",
               (int)r->rtype,reloc_name[r->rtype],ls->name,r->offset,r->addend);
    }

    s = r->relocsect.lnk->base;
    a = r->addend;
    p = ls->base + r->offset;
    val = 0;

    switch (r->rtype) {

      case R_NONE:
        continue;

      case R_ABS:
        val = s+a;
        break;

      case R_PC:
        val = s+a-p;
        break;

#if 0 /* @@@ shouldn't occur - already resolved by linker_relocate() ??? */
      case R_SD:
        val = s+a - _SDA_BASE_; /* @@@ */
        break;
#endif

      default:
        ierror("%sReloc type %d (%s) is currently not supported",
               fn,(int)r->rtype,reloc_name[r->rtype]);
        break;
    }

    if (val = writesection(gv,ls->data+r->offset,r,val)) {
      struct RelocInsert *ri;

      /* Calculated value doesn't fit into relocation type x ... */
      if (ri = r->insert)
        error(35,gv->dest_name,ls->name,r->offset,val,reloc_name[r->rtype],
              (int)ri->bpos,(int)ri->bsiz,ri->mask);
      else
        ierror("%sReloc (%s+%lx), type=%s, without RelocInsert",
               fn,ls->name,r->offset,reloc_name[r->rtype]);
    }
  }
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x60(%rsp)
movq %rsi, 0x58(%rsp)
leaq 0x2429d(%rip), %rax     # 0x357a2
movq %rax, 0x50(%rsp)
cmpq $0x0, 0x58(%rsp)
jne 0x11517
jmp 0x11778
movq 0x58(%rsp), %rax
movq 0x80(%rax), %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rax
cmpq $0x0, (%rax)
je 0x11778
movq 0x48(%rsp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x115a5
movq 0x48(%rsp), %rax
movzbl 0x39(%rax), %eax
andl $0xc0, %eax
cmpl $0x0, %eax
je 0x1155b
jmp 0x11766
movq 0x48(%rsp), %rax
movzbl 0x38(%rax), %esi
movq 0x48(%rsp), %rax
movzbl 0x38(%rax), %eax
movl %eax, %ecx
leaq 0x2e62a(%rip), %rax     # 0x3fba0
movq (%rax,%rcx,8), %rdx
movq 0x58(%rsp), %rax
movq 0x18(%rax), %rcx
movq 0x48(%rsp), %rax
movq 0x20(%rax), %r8
movq 0x48(%rsp), %rax
movq 0x28(%rax), %r9
leaq 0x24215(%rip), %rdi     # 0x357b1
movb $0x0, %al
callq 0x8ae0
jmp 0x115a5
movq 0x48(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x40(%rax), %rax
movq %rax, 0x40(%rsp)
movq 0x48(%rsp), %rax
movq 0x28(%rax), %rax
movq %rax, 0x38(%rsp)
movq 0x58(%rsp), %rax
movq 0x40(%rax), %rax
movq 0x48(%rsp), %rcx
movq 0x20(%rcx), %rcx
addq %rcx, %rax
movq %rax, 0x30(%rsp)
movq $0x0, 0x28(%rsp)
movq 0x48(%rsp), %rax
movzbl 0x38(%rax), %eax
movl %eax, 0x1c(%rsp)
testl %eax, %eax
je 0x11611
jmp 0x115fb
movl 0x1c(%rsp), %eax
subl $0x1, %eax
je 0x11616
jmp 0x11606
movl 0x1c(%rsp), %eax
subl $0x2, %eax
je 0x11627
jmp 0x1163d
jmp 0x11766
movq 0x40(%rsp), %rax
addq 0x38(%rsp), %rax
movq %rax, 0x28(%rsp)
jmp 0x1166f
movq 0x40(%rsp), %rax
addq 0x38(%rsp), %rax
subq 0x30(%rsp), %rax
movq %rax, 0x28(%rsp)
jmp 0x1166f
movq 0x50(%rsp), %rsi
movq 0x48(%rsp), %rax
movzbl 0x38(%rax), %edx
movq 0x48(%rsp), %rax
movzbl 0x38(%rax), %eax
movl %eax, %ecx
leaq 0x2e543(%rip), %rax     # 0x3fba0
movq (%rax,%rcx,8), %rcx
leaq 0x241a0(%rip), %rdi     # 0x35808
movb $0x0, %al
callq 0x8ae0
movq 0x60(%rsp), %rdi
movq 0x58(%rsp), %rax
movq 0x78(%rax), %rsi
movq 0x48(%rsp), %rax
addq 0x20(%rax), %rsi
movq 0x48(%rsp), %rdx
movq 0x28(%rsp), %rcx
callq 0x110c0
movq %rax, 0x28(%rsp)
cmpq $0x0, %rax
je 0x11764
movq 0x48(%rsp), %rax
movq 0x30(%rax), %rax
movq %rax, 0x20(%rsp)
cmpq $0x0, %rax
je 0x11727
movq 0x60(%rsp), %rax
movq 0x48(%rax), %rsi
movq 0x58(%rsp), %rax
movq 0x18(%rax), %rdx
movq 0x48(%rsp), %rax
movq 0x20(%rax), %rcx
movq 0x28(%rsp), %r8
movq 0x48(%rsp), %rax
movzbl 0x38(%rax), %eax
movl %eax, %edi
leaq 0x2e4b6(%rip), %rax     # 0x3fba0
movq (%rax,%rdi,8), %r9
movq 0x20(%rsp), %rax
movzwl 0x8(%rax), %r11d
movq 0x20(%rsp), %rax
movzwl 0xa(%rax), %r10d
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movl $0x23, %edi
movl %r11d, (%rsp)
movl %r10d, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x8c00
jmp 0x11762
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rax
movq 0x18(%rax), %rdx
movq 0x48(%rsp), %rax
movq 0x20(%rax), %rcx
movq 0x48(%rsp), %rax
movzbl 0x38(%rax), %eax
movl %eax, %edi
leaq 0x2e450(%rip), %rax     # 0x3fba0
movq (%rax,%rdi,8), %r8
leaq 0x240dd(%rip), %rdi     # 0x35838
movb $0x0, %al
callq 0x8ae0
jmp 0x11764
jmp 0x11766
movq 0x48(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x48(%rsp)
jmp 0x11528
addq $0x68, %rsp
retq
nopl (%rax)