// File: /workspace/github_c_makefile_star2_O0/deplinenoise[P]vlink/linker.c
// Function: linker_resolve
void linker_resolve(struct GlobalVars *gv)
/* Resolve all symbol references and pull the required objects into */
/* the gv->selobjects list. */
{
  bool constructors_made = FALSE;
  bool pseudo_dynlink = (fff[gv->dest_format]->flags&FFF_PSEUDO_DYNLINK)!=0;
  struct ObjectUnit *obj = (struct ObjectUnit *)gv->selobjects.first;
  static const char *pulltxt = " needed due to ";

  if (gv->dest_sharedobj || gv->dyn_exp_all) {
    gv->dynamic = TRUE;
    init_dynlink(gv);
  }
  else
    gv->dynamic = FALSE;  /* set to true, when first shared object found */

  if (gv->trace_file)
    fprintf(gv->trace_file,"\nDigesting symbol information:\n\n");

  if (obj->n.next == NULL)
    return;  /* no objects in list */

  do {
    struct Section *sec;
    struct Reloc *xref;
    struct Symbol *xdef;
    struct ObjectUnit *pull_unit;

    /* all sections of this object are checked for external references */
    for (sec=(struct Section *)obj->sections.first;
         sec->n.next!=NULL; sec=(struct Section *)sec->n.next) {

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

        if (xref->rtype == R_LOADREL) {
          /* addend offsets to load address, nothing to resolve */
          continue;
        }

        /* find a global symbol with this name in any object or library */
        xdef = findsymbol(gv,sec,xref->xrefname);

        if (xdef!=NULL && xref->rtype==R_LOCALPC) {
          /* R_LOCALPC only accepts symbols which are defined in the
             same ObjectUnit as the reference. */
          if (xdef->relsect->obj != obj)
            xdef = NULL;  /* discard symbol from other object */
        }

        if (xdef == NULL) {
          /* check if reference can be resolved by a linker symbol */
          if (!(xdef = lnksymbol(gv,sec,xref))) {

            /* ref. to undefined symbol is only an error for executables */
            if (!gv->dest_object && !gv->dest_sharedobj) {
              if (xref->flags & RELF_WEAK) {
                /* weak references default to 0 */
                xdef = addlnksymbol(gv,xref->xrefname,0,SYM_RELOC,0,
                                    SYMI_NOTYPE,SYMB_LOCAL,0);
                xdef->relsect = dummy_section(gv,obj);
              }
              else {
                print_function_name(sec,xref->offset);
                error(21,getobjname(sec->obj),sec->name,xref->offset,
                      xref->xrefname);
                continue;
              }
            }
            else
              continue;
          }
        }
        /* reference has been resolved after this point */
        if (trace_sym_access(gv,xref->xrefname))
          fprintf(stderr,"Symbol %s referenced from %s\n",
                  xref->xrefname,getobjname(sec->obj));

        /* turn LOCALPC into a PC reloc, once resolved by a local symbol */
        if (xref->rtype == R_LOCALPC)
          xref->rtype = R_PC;

        /* link with symbol's unit */
        if (xdef->relsect && xdef->relsect->type != ST_TMP) {
          pull_unit = xdef->relsect->obj;

          switch (pull_unit->lnkfile->type) {

            case ID_ARTIFICIAL:
              /* linker-generated object - insert it behind the curr. obj. */
              if (!(pull_unit->flags & OUF_LINKED)) {
                if (gv->map_file) {
                  fprintf(gv->map_file,
                          "artificial object (%s) created due to %s\n",
                          pull_unit->objname,xref->xrefname);
                  /* "artificial object (name.o) created due to @__name" */
                }
                insertbehind(&obj->n,&pull_unit->n);
                pull_unit->flags |= OUF_LINKED;
              }
              /* turn into a normal object */
              pull_unit->lnkfile->type = ID_OBJECT;
              xref->relocsect.symbol = xdef;  /* xref was resolved */
              break;

            case ID_SHAREDOBJ:
              if (!(pull_unit->flags & OUF_LINKED)) {
                if (gv->map_file) {
                  fprintf(gv->map_file,"%s%s%s\n",
                          pull_unit->lnkfile->pathname,pulltxt,xref->xrefname);
                  /* Example: "/usr/lib/libc.so.12.0 needed due to _atexit" */
                }
                insertbehind(&obj->n,remnode(&pull_unit->n));
                add_priptrs(gv,pull_unit);
                pull_unit->flags |= OUF_LINKED;
                reenter_global_objsyms(gv,pull_unit);
                if (!pseudo_dynlink) {
                  if (!gv->dynamic) {
                    gv->dynamic = TRUE;  /* we're doing dynamic linking! */
                    init_dynlink(gv);
                  }
                  /* declare the shared object as "needed" */
                  dyn_so_needed(gv,pull_unit);
                }
              }

              if (!gv->dest_object && !pseudo_dynlink) {
                /* ref. to a shared object's symbol needs special treatment */
                switch (xref->rtype) {
                  case R_ABS:
                  case R_PC:
                    if (xdef->info == SYMI_FUNC) {
                      /* abs. or rel. function calls create a PLT entry */
                      xdef = dyn_ext_entry(gv,xdef,xref,PLT_ENTRY);
                    }
                    else {
                      /* alloc bss space and R_COPY from shared object */
                      xdef = dyn_ext_entry(gv,xdef,xref,BSS_ENTRY);
                    }
                    break;
                  case R_GOT:
                  case R_GOTPC:
                  case R_GOTOFF:
                  case R_PLT:
                  case R_PLTPC:
                  case R_PLTOFF:
                  case R_GLOBDAT:
                  case R_JMPSLOT:
                  case R_COPY:
                    /* types are already correct for referencing a shared obj. */
                    break;
                  default:
                    ierror("linker_resolve(): Unsupported reloc %s referencing "
                           "shared object symbol %s",
                           reloc_name[xref->rtype],xref->xrefname);
                    break;
                }
                xref->relocsect.symbol = xdef;  /* xref was resolved */
              }
              break;

            case ID_LIBARCH:
              if (!(pull_unit->flags & OUF_LINKED)) {
                if (gv->map_file) {
                  fprintf(gv->map_file,"%s (%s)%s%s\n",
                          pull_unit->lnkfile->pathname,pull_unit->objname,
                          pulltxt,xref->xrefname);
                  /* "/usr/lib/libc.a (atexit.o) needed due to _atexit" */
                }
                insertbehind(&obj->n,remnode(&pull_unit->n));
                add_priptrs(gv,pull_unit);
                pull_unit->flags |= OUF_LINKED;
                reenter_global_objsyms(gv,pull_unit);
              }
              /* fall through */

            default:
              xref->relocsect.symbol = xdef;  /* xref was resolved */
              break;
          }

          /* Handle explicit GOT and PLT references */
          if (!gv->dest_object) {
            switch (xref->rtype) {
              case R_GOT:
              case R_GOTPC:
              case R_GOTOFF:
                xref->relocsect.symbol = dyn_ext_entry(gv,xdef,xref,GOT_ENTRY);
                break;
              case R_PLT:
              case R_PLTPC:
              case R_PLTOFF:
                xref->relocsect.symbol = dyn_ext_entry(gv,xdef,xref,PLT_ENTRY);
                break;
            }
          }

          /* is it a reference from a shared object to one of our symbols? */
          if (obj->lnkfile->type==ID_SHAREDOBJ
              && pull_unit->lnkfile->type!=ID_SHAREDOBJ)
            dyn_export(gv,xdef);  /* then we have to export it */
        }
        else
          xref->relocsect.symbol = xdef;

        xdef->flags |= SYMF_REFERENCED;
      }
    }

    if (obj->n.next->next == NULL && !constructors_made) {
      make_constructors(gv);  /* Con-/Destructor object always at last */
      constructors_made = TRUE;
    }
    obj = (struct ObjectUnit *)obj->n.next;
  }
  while (obj->n.next);
}

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x80(%rsp)
movl $0x0, 0x7c(%rsp)
movq 0x80(%rsp), %rax
movzbl 0x50(%rax), %eax
movl %eax, %ecx
leaq 0x35cc4(%rip), %rax     # 0x3fa30
movq (%rax,%rcx,8), %rax
movl 0xac(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x78(%rsp)
movq 0x80(%rsp), %rax
movq 0x138(%rax), %rax
movq %rax, 0x70(%rsp)
movq 0x80(%rsp), %rax
cmpl $0x0, 0x58(%rax)
jne 0x9db8
movq 0x80(%rsp), %rax
cmpl $0x0, 0x5c(%rax)
je 0x9dd9
movq 0x80(%rsp), %rax
movl $0x1, 0x240(%rax)
movq 0x80(%rsp), %rdi
callq 0xa590
jmp 0x9deb
movq 0x80(%rsp), %rax
movl $0x0, 0x240(%rax)
movq 0x80(%rsp), %rax
cmpq $0x0, 0xa0(%rax)
je 0x9e1a
movq 0x80(%rsp), %rax
movq 0xa0(%rax), %rdi
leaq 0x2b387(%rip), %rsi     # 0x3519a
movb $0x0, %al
callq 0x5150
movq 0x70(%rsp), %rax
cmpq $0x0, (%rax)
jne 0x9e2a
jmp 0xa57b
jmp 0x9e2c
movq 0x70(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, 0x68(%rsp)
movq 0x68(%rsp), %rax
cmpq $0x0, (%rax)
je 0xa535
movq 0x68(%rsp), %rax
movq 0x68(%rax), %rax
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rax
cmpq $0x0, (%rax)
je 0xa521
movq 0x60(%rsp), %rax
movzbl 0x38(%rax), %eax
cmpl $0xd, %eax
jne 0x9e79
jmp 0xa50f
movq 0x80(%rsp), %rdi
movq 0x68(%rsp), %rsi
movq 0x60(%rsp), %rax
movq 0x10(%rax), %rdx
callq 0xf580
movq %rax, 0x58(%rsp)
cmpq $0x0, 0x58(%rsp)
je 0x9ece
movq 0x60(%rsp), %rax
movzbl 0x38(%rax), %eax
cmpl $0xc, %eax
jne 0x9ece
movq 0x58(%rsp), %rax
movq 0x38(%rax), %rax
movq 0x10(%rax), %rax
cmpq 0x70(%rsp), %rax
je 0x9ecc
movq $0x0, 0x58(%rsp)
jmp 0x9ece
cmpq $0x0, 0x58(%rsp)
jne 0x9fe9
movq 0x80(%rsp), %rdi
movq 0x68(%rsp), %rsi
movq 0x60(%rsp), %rdx
callq 0xa5e0
movq %rax, 0x58(%rsp)
cmpq $0x0, %rax
jne 0x9fe7
movq 0x80(%rsp), %rax
cmpl $0x0, 0x54(%rax)
jne 0x9fe0
movq 0x80(%rsp), %rax
cmpl $0x0, 0x58(%rax)
jne 0x9fe0
movq 0x60(%rsp), %rax
movzbl 0x39(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x9f8e
movq 0x80(%rsp), %rdi
movq 0x60(%rsp), %rax
movq 0x10(%rax), %rsi
xorl %eax, %eax
movl %eax, %edx
movl $0x2, %ecx
xorl %r9d, %r9d
movl %r9d, %r8d
movl $0x1, (%rsp)
movl $0x0, 0x8(%rsp)
callq 0x101f0
movq %rax, 0x58(%rsp)
movq 0x80(%rsp), %rdi
movq 0x70(%rsp), %rsi
callq 0x12920
movq %rax, %rcx
movq 0x58(%rsp), %rax
movq %rcx, 0x38(%rax)
jmp 0x9fde
movq 0x68(%rsp), %rdi
movq 0x60(%rsp), %rax
movq 0x20(%rax), %rsi
callq 0x8fb0
movq 0x68(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x8f00
movq %rax, %rsi
movq 0x68(%rsp), %rax
movq 0x20(%rax), %rdx
movq 0x60(%rsp), %rax
movq 0x20(%rax), %rcx
movq 0x60(%rsp), %rax
movq 0x10(%rax), %r8
movl $0x15, %edi
movb $0x0, %al
callq 0x8c00
jmp 0xa50f
jmp 0x9fe5
jmp 0xa50f
jmp 0x9fe7
jmp 0x9fe9
movq 0x80(%rsp), %rdi
movq 0x60(%rsp), %rax
movq 0x10(%rax), %rsi
callq 0x9330
cmpl $0x0, %eax
je 0xa04a
movq 0x34fed(%rip), %rax     # 0x3eff8
movq (%rax), %rax
movq %rax, 0x40(%rsp)
movq 0x60(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x48(%rsp)
movq 0x68(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x8f00
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rdx
movq %rax, %rcx
leaq 0x2b178(%rip), %rsi     # 0x351bb
movb $0x0, %al
callq 0x5150
movq 0x60(%rsp), %rax
movzbl 0x38(%rax), %eax
cmpl $0xc, %eax
jne 0xa061
movq 0x60(%rsp), %rax
movb $0x2, 0x38(%rax)
movq 0x58(%rsp), %rax
cmpq $0x0, 0x38(%rax)
je 0xa4f2
movq 0x58(%rsp), %rax
movq 0x38(%rax), %rax
movzbl 0x2c(%rax), %eax
cmpl $0x4, %eax
je 0xa4f2
movq 0x58(%rsp), %rax
movq 0x38(%rax), %rax
movq 0x10(%rax), %rax
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rax
movq 0x10(%rax), %rax
movzbl 0x39(%rax), %eax
movl %eax, 0x3c(%rsp)
subl $0x3, %eax
je 0xa0d2
jmp 0xa0b1
movl 0x3c(%rsp), %eax
subl $0x4, %eax
je 0xa16c
jmp 0xa0c0
movl 0x3c(%rsp), %eax
subl $0x8, %eax
je 0xa35b
jmp 0xa425
movq 0x50(%rsp), %rax
movzwl 0x80(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0xa14c
movq 0x80(%rsp), %rax
cmpq $0x0, 0x90(%rax)
je 0xa127
movq 0x80(%rsp), %rax
movq 0x90(%rax), %rdi
movq 0x50(%rsp), %rax
movq 0x18(%rax), %rdx
movq 0x60(%rsp), %rax
movq 0x10(%rax), %rcx
leaq 0x2b0b9(%rip), %rsi     # 0x351d9
movb $0x0, %al
callq 0x5150
movq 0x70(%rsp), %rdi
movq 0x50(%rsp), %rsi
callq 0x73c0
movq 0x50(%rsp), %rax
movzwl 0x80(%rax), %ecx
orl $0x1, %ecx
movw %cx, 0x80(%rax)
movq 0x50(%rsp), %rax
movq 0x10(%rax), %rax
movb $0x1, 0x39(%rax)
movq 0x58(%rsp), %rcx
movq 0x60(%rsp), %rax
movq %rcx, 0x18(%rax)
jmp 0xa433
movq 0x50(%rsp), %rax
movzwl 0x80(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0xa276
movq 0x80(%rsp), %rax
cmpq $0x0, 0x90(%rax)
je 0xa1d0
movq 0x80(%rsp), %rax
movq 0x90(%rax), %rdi
movq 0x50(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rdx
movq 0x3582f(%rip), %rcx     # 0x3f9e8
movq 0x60(%rsp), %rax
movq 0x10(%rax), %r8
leaq 0x2b03a(%rip), %rsi     # 0x35203
movb $0x0, %al
callq 0x5150
movq 0x70(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x50(%rsp), %rdi
callq 0x7530
movq 0x30(%rsp), %rdi
movq %rax, %rsi
callq 0x73c0
movq 0x80(%rsp), %rdi
movq 0x50(%rsp), %rsi
callq 0x11920
movq 0x50(%rsp), %rax
movzwl 0x80(%rax), %ecx
orl $0x1, %ecx
movw %cx, 0x80(%rax)
movq 0x80(%rsp), %rdi
movq 0x50(%rsp), %rsi
callq 0x10620
cmpl $0x0, 0x78(%rsp)
jne 0xa274
movq 0x80(%rsp), %rax
cmpl $0x0, 0x240(%rax)
jne 0xa262
movq 0x80(%rsp), %rax
movl $0x1, 0x240(%rax)
movq 0x80(%rsp), %rdi
callq 0xa590
movq 0x80(%rsp), %rdi
movq 0x50(%rsp), %rsi
callq 0xa680
jmp 0xa276
movq 0x80(%rsp), %rax
cmpl $0x0, 0x54(%rax)
jne 0xa356
cmpl $0x0, 0x78(%rsp)
jne 0xa356
movq 0x60(%rsp), %rax
movzbl 0x38(%rax), %eax
movl %eax, 0x2c(%rsp)
decl %eax
subl $0x2, %eax
jb 0xa2c5
jmp 0xa2a9
movl 0x2c(%rsp), %eax
addl $-0x3, %eax
subl $0x7, %eax
jb 0xa319
jmp 0xa2b7
movl 0x2c(%rsp), %eax
addl $-0xe, %eax
subl $0x2, %eax
jb 0xa319
jmp 0xa31b
movq 0x58(%rsp), %rax
movzbl 0x42(%rax), %eax
cmpl $0x2, %eax
jne 0xa2f6
movq 0x80(%rsp), %rdi
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdx
movl $0x2, %ecx
callq 0xa6c0
movq %rax, 0x58(%rsp)
jmp 0xa317
movq 0x80(%rsp), %rdi
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdx
movl $0x3, %ecx
callq 0xa6c0
movq %rax, 0x58(%rsp)
jmp 0xa348
jmp 0xa348
movq 0x60(%rsp), %rax
movzbl 0x38(%rax), %eax
movl %eax, %ecx
leaq 0x35873(%rip), %rax     # 0x3fba0
movq (%rax,%rcx,8), %rsi
movq 0x60(%rsp), %rax
movq 0x10(%rax), %rdx
leaq 0x2aeca(%rip), %rdi     # 0x3520b
movb $0x0, %al
callq 0x8ae0
movq 0x58(%rsp), %rcx
movq 0x60(%rsp), %rax
movq %rcx, 0x18(%rax)
jmp 0xa433
movq 0x50(%rsp), %rax
movzwl 0x80(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0xa423
movq 0x80(%rsp), %rax
cmpq $0x0, 0x90(%rax)
je 0xa3c8
movq 0x80(%rsp), %rax
movq 0x90(%rax), %rdi
movq 0x50(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rdx
movq 0x50(%rsp), %rax
movq 0x18(%rax), %rcx
movq 0x35637(%rip), %r8      # 0x3f9e8
movq 0x60(%rsp), %rax
movq 0x10(%rax), %r9
leaq 0x2ae95(%rip), %rsi     # 0x35256
movb $0x0, %al
callq 0x5150
movq 0x70(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x50(%rsp), %rdi
callq 0x7530
movq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0x73c0
movq 0x80(%rsp), %rdi
movq 0x50(%rsp), %rsi
callq 0x11920
movq 0x50(%rsp), %rax
movzwl 0x80(%rax), %ecx
orl $0x1, %ecx
movw %cx, 0x80(%rax)
movq 0x80(%rsp), %rdi
movq 0x50(%rsp), %rsi
callq 0x10620
jmp 0xa425
movq 0x58(%rsp), %rcx
movq 0x60(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x80(%rsp), %rax
cmpl $0x0, 0x54(%rax)
jne 0xa4ba
movq 0x60(%rsp), %rax
movzbl 0x38(%rax), %eax
movl %eax, 0x1c(%rsp)
addl $-0x3, %eax
subl $0x3, %eax
jb 0xa466
jmp 0xa458
movl 0x1c(%rsp), %eax
addl $-0x7, %eax
subl $0x3, %eax
jb 0xa490
jmp 0xa4b8
movq 0x80(%rsp), %rdi
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdx
movl $0x1, %ecx
callq 0xa6c0
movq %rax, %rcx
movq 0x60(%rsp), %rax
movq %rcx, 0x18(%rax)
jmp 0xa4b8
movq 0x80(%rsp), %rdi
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdx
movl $0x2, %ecx
callq 0xa6c0
movq %rax, %rcx
movq 0x60(%rsp), %rax
movq %rcx, 0x18(%rax)
jmp 0xa4ba
movq 0x70(%rsp), %rax
movq 0x10(%rax), %rax
movzbl 0x39(%rax), %eax
cmpl $0x4, %eax
jne 0xa4f0
movq 0x50(%rsp), %rax
movq 0x10(%rax), %rax
movzbl 0x39(%rax), %eax
cmpl $0x4, %eax
je 0xa4f0
movq 0x80(%rsp), %rdi
movq 0x58(%rsp), %rsi
callq 0xa780
jmp 0xa500
movq 0x58(%rsp), %rcx
movq 0x60(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x58(%rsp), %rax
movzbl 0x41(%rax), %ecx
orl $0x2, %ecx
movb %cl, 0x41(%rax)
movq 0x60(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x60(%rsp)
jmp 0x9e57
jmp 0xa523
movq 0x68(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x68(%rsp)
jmp 0x9e3a
movq 0x70(%rsp), %rax
movq (%rax), %rax
cmpq $0x0, (%rax)
jne 0xa55f
cmpl $0x0, 0x7c(%rsp)
jne 0xa55f
movq 0x80(%rsp), %rdi
callq 0x12b80
movl $0x1, 0x7c(%rsp)
movq 0x70(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rax
cmpq $0x0, (%rax)
jne 0x9e2c
addq $0x88, %rsp
retq
nopw %cs:(%rax,%rax)