// File: /workspace/github_c_makefile_star2_O0/deplinenoise[P]vlink/linker.c
// Function: linker_relrefs
void linker_relrefs(struct GlobalVars *gv)
/* All relocations and unresolved xrefs with a relative reference
   to other sections are collected. A second task is to detect
   and handle base-relative and GOT/PLT references. */
{
  struct ObjectUnit *obj;
  struct Section *sec;
  struct Symbol *sdabase = NULL;
  struct Symbol *sda2base = NULL;
  struct Symbol *r13init = NULL;

  for (obj=(struct ObjectUnit *)gv->selobjects.first;
       obj->n.next!=NULL; obj=(struct ObjectUnit *)obj->n.next) {

    for (sec=(struct Section *)obj->sections.first;
         sec->n.next!=NULL; sec=(struct Section *)sec->n.next) {
      struct RelRef **rr = &sec->relrefs;
      struct Symbol *xdef;
      struct Reloc *xref,*reloc;

      for (*rr=NULL,xref=(struct Reloc *)sec->xrefs.first;
           xref->n.next!=NULL; xref=(struct Reloc *)xref->n.next) {

        if (xdef = xref->relocsect.symbol) {
          if (xdef->relsect!=NULL &&
              (xdef->type==SYM_RELOC || xdef->type==SYM_COMMON)) {

            if ((xref->rtype==R_SD || xref->rtype==R_SD21 ||
                 xref->rtype==R_MOSDREL) && xdef->type==SYM_COMMON) {
                /* small data common symbol - assign .scommon section */
                xdef->relsect = scommon_section(gv,xdef->relsect->obj);
            }

            if (xref->rtype==R_PC && xdef->relsect!=sec) {
              /* relative reference to different section */
              addrelref(rr,xdef->relsect);
            }

            else if (xref->rtype==R_SD || xref->rtype==R_MOSDREL) {
              /* other section is accessed base relative from this one */
              xdef->relsect->flags |= SF_SMALLDATA;
              if (!gv->textbaserel && xdef->relsect->type==ST_CODE)
                error(121,getobjname(sec->obj),sec->name,xref->offset);
            }
          }
        }
      }

      for (reloc=(struct Reloc *)sec->relocs.first;
           reloc->n.next!=NULL; reloc=(struct Reloc *)reloc->n.next) {

        if (reloc->rtype==R_PC && reloc->relocsect.ptr!=sec) {
          /* relative reference to different section */
          addrelref(rr,reloc->relocsect.ptr);
        }

        else if (reloc->rtype==R_GOT || reloc->rtype==R_GOTPC) {
          /* a local relocation to a GOT entry may create that entry */
          dyn_reloc_entry(gv,reloc,GOT_LOCAL);
        }

        else if (reloc->rtype==R_PLT || reloc->rtype==R_PLTPC) {
          /* a local relocation to a PLT entry may create that entry */
          dyn_reloc_entry(gv,reloc,PLT_LOCAL);
        }

        else if (reloc->rtype == R_SD) {
          /* other section is accessed base relative from this one */
          reloc->relocsect.ptr->flags |= SF_SMALLDATA;
          if (!sdabase) {
            /* R_SD relocation implies a reference to _SDA_BASE_ */
            if (sdabase = find_any_symbol(gv,sec,sdabase_name))
              sdabase->flags |= SYMF_REFERENCED;
          }
          if (!gv->textbaserel && reloc->relocsect.ptr->type==ST_CODE)
            error(121,getobjname(sec->obj),sec->name,reloc->offset);
        }

        else if (reloc->rtype == R_SD2) {
          if (!sda2base) {
            /* R_SD2 relocation implies a reference to _SDA2_BASE_ */
            if (sda2base = find_any_symbol(gv,sec,sda2base_name))
              sda2base->flags |= SYMF_REFERENCED;
          }
        }

        else if (reloc->rtype == R_MOSDREL) {
          /* other section is accessed base relative from this one */
          reloc->relocsect.ptr->flags |= SF_SMALLDATA;
          if (!r13init) {
            /* R_MOSDREL relocation implies a reference to __r13_init */
            if (r13init = find_any_symbol(gv,sec,r13init_name))
              r13init->flags |= SYMF_REFERENCED;
          }
          if (!gv->textbaserel && reloc->relocsect.ptr->type==ST_CODE)
            error(121,getobjname(sec->obj),sec->name,reloc->offset);
        }

      }
    }
  }
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movq $0x0, 0x38(%rsp)
movq $0x0, 0x30(%rsp)
movq $0x0, 0x28(%rsp)
movq 0x50(%rsp), %rax
movq 0x138(%rax), %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rax
cmpq $0x0, (%rax)
je 0xaca0
movq 0x48(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rax
cmpq $0x0, (%rax)
je 0xac8c
movq 0x40(%rsp), %rax
addq $0x80, %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
movq $0x0, (%rax)
movq 0x40(%rsp), %rax
movq 0x68(%rax), %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
cmpq $0x0, (%rax)
je 0xa9ed
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, %rax
je 0xa9d9
movq 0x18(%rsp), %rax
cmpq $0x0, 0x38(%rax)
je 0xa9d7
movq 0x18(%rsp), %rax
movzbl 0x40(%rax), %eax
cmpl $0x2, %eax
je 0xa8c2
movq 0x18(%rsp), %rax
movzbl 0x40(%rax), %eax
cmpl $0x3, %eax
jne 0xa9d7
movq 0x10(%rsp), %rax
movzbl 0x38(%rax), %eax
cmpl $0xa, %eax
je 0xa8ec
movq 0x10(%rsp), %rax
movzbl 0x38(%rax), %eax
cmpl $0x21, %eax
je 0xa8ec
movq 0x10(%rsp), %rax
movzbl 0x38(%rax), %eax
cmpl $0x22, %eax
jne 0xa91d
movq 0x18(%rsp), %rax
movzbl 0x40(%rax), %eax
cmpl $0x3, %eax
jne 0xa91d
movq 0x50(%rsp), %rdi
movq 0x18(%rsp), %rax
movq 0x38(%rax), %rax
movq 0x10(%rax), %rsi
callq 0x12800
movq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x38(%rax)
movq 0x10(%rsp), %rax
movzbl 0x38(%rax), %eax
cmpl $0x2, %eax
jne 0xa953
movq 0x18(%rsp), %rax
movq 0x38(%rax), %rax
cmpq 0x40(%rsp), %rax
je 0xa953
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rax
movq 0x38(%rax), %rsi
callq 0xacb0
jmp 0xa9d5
movq 0x10(%rsp), %rax
movzbl 0x38(%rax), %eax
cmpl $0xa, %eax
je 0xa96f
movq 0x10(%rsp), %rax
movzbl 0x38(%rax), %eax
cmpl $0x22, %eax
jne 0xa9d3
movq 0x18(%rsp), %rax
movq 0x38(%rax), %rax
movzbl 0x2d(%rax), %ecx
orl $0x4, %ecx
movb %cl, 0x2d(%rax)
movq 0x50(%rsp), %rax
cmpl $0x0, 0x84(%rax)
jne 0xa9d1
movq 0x18(%rsp), %rax
movq 0x38(%rax), %rax
movzbl 0x2c(%rax), %eax
cmpl $0x1, %eax
jne 0xa9d1
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x8f00
movq %rax, %rsi
movq 0x40(%rsp), %rax
movq 0x20(%rax), %rdx
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rcx
movl $0x79, %edi
movb $0x0, %al
callq 0x8c00
jmp 0xa9d3
jmp 0xa9d5
jmp 0xa9d7
jmp 0xa9d9
jmp 0xa9db
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x10(%rsp)
jmp 0xa86b
movq 0x40(%rsp), %rax
movq 0x50(%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
cmpq $0x0, (%rax)
je 0xac78
movq 0x8(%rsp), %rax
movzbl 0x38(%rax), %eax
cmpl $0x2, %eax
jne 0xaa40
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
cmpq 0x40(%rsp), %rax
je 0xaa40
movq 0x20(%rsp), %rdi
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rsi
callq 0xacb0
jmp 0xac64
movq 0x8(%rsp), %rax
movzbl 0x38(%rax), %eax
cmpl $0x3, %eax
je 0xaa5c
movq 0x8(%rsp), %rax
movzbl 0x38(%rax), %eax
cmpl $0x4, %eax
jne 0xaa75
movq 0x50(%rsp), %rdi
movq 0x8(%rsp), %rsi
movl $0x4, %edx
callq 0xad30
jmp 0xac62
movq 0x8(%rsp), %rax
movzbl 0x38(%rax), %eax
cmpl $0x7, %eax
je 0xaa91
movq 0x8(%rsp), %rax
movzbl 0x38(%rax), %eax
cmpl $0x8, %eax
jne 0xaaaa
movq 0x50(%rsp), %rdi
movq 0x8(%rsp), %rsi
movl $0x5, %edx
callq 0xad30
jmp 0xac60
movq 0x8(%rsp), %rax
movzbl 0x38(%rax), %eax
cmpl $0xa, %eax
jne 0xab5d
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movzbl 0x2d(%rax), %ecx
orl $0x4, %ecx
movb %cl, 0x2d(%rax)
cmpq $0x0, 0x38(%rsp)
jne 0xab09
movq 0x50(%rsp), %rdi
movq 0x40(%rsp), %rsi
leaq 0x2aafd(%rip), %rdx     # 0x355e5
callq 0x105c0
movq %rax, 0x38(%rsp)
cmpq $0x0, %rax
je 0xab07
movq 0x38(%rsp), %rax
movzbl 0x41(%rax), %ecx
orl $0x2, %ecx
movb %cl, 0x41(%rax)
jmp 0xab09
movq 0x50(%rsp), %rax
cmpl $0x0, 0x84(%rax)
jne 0xab58
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movzbl 0x2c(%rax), %eax
cmpl $0x1, %eax
jne 0xab58
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x8f00
movq %rax, %rsi
movq 0x40(%rsp), %rax
movq 0x20(%rax), %rdx
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rcx
movl $0x79, %edi
movb $0x0, %al
callq 0x8c00
jmp 0xac5e
movq 0x8(%rsp), %rax
movzbl 0x38(%rax), %eax
cmpl $0x20, %eax
jne 0xabaa
cmpq $0x0, 0x30(%rsp)
jne 0xaba5
movq 0x50(%rsp), %rdi
movq 0x40(%rsp), %rsi
leaq 0x2aa6c(%rip), %rdx     # 0x355f0
callq 0x105c0
movq %rax, 0x30(%rsp)
cmpq $0x0, %rax
je 0xaba3
movq 0x30(%rsp), %rax
movzbl 0x41(%rax), %ecx
orl $0x2, %ecx
movb %cl, 0x41(%rax)
jmp 0xaba5
jmp 0xac5c
movq 0x8(%rsp), %rax
movzbl 0x38(%rax), %eax
cmpl $0x22, %eax
jne 0xac5a
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movzbl 0x2d(%rax), %ecx
orl $0x4, %ecx
movb %cl, 0x2d(%rax)
cmpq $0x0, 0x28(%rsp)
jne 0xac09
movq 0x50(%rsp), %rdi
movq 0x40(%rsp), %rsi
leaq 0x2aa5d(%rip), %rdx     # 0x35645
callq 0x105c0
movq %rax, 0x28(%rsp)
cmpq $0x0, %rax
je 0xac07
movq 0x28(%rsp), %rax
movzbl 0x41(%rax), %ecx
orl $0x2, %ecx
movb %cl, 0x41(%rax)
jmp 0xac09
movq 0x50(%rsp), %rax
cmpl $0x0, 0x84(%rax)
jne 0xac58
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movzbl 0x2c(%rax), %eax
cmpl $0x1, %eax
jne 0xac58
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x8f00
movq %rax, %rsi
movq 0x40(%rsp), %rax
movq 0x20(%rax), %rdx
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rcx
movl $0x79, %edi
movb $0x0, %al
callq 0x8c00
jmp 0xac5a
jmp 0xac5c
jmp 0xac5e
jmp 0xac60
jmp 0xac62
jmp 0xac64
jmp 0xac66
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x8(%rsp)
jmp 0xa9fb
jmp 0xac7a
movq 0x40(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x40(%rsp)
jmp 0xa832
jmp 0xac8e
movq 0x48(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x48(%rsp)
jmp 0xa815
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)