// File: /workspace/github_c_makefile_star2_O0/deplinenoise[P]vlink/linker.c
// Function: linker_copy
void linker_copy(struct GlobalVars *gv)
/* Merge contents of linked sections, fix symbol offsets and
   allocate common symbol data. */
{
  struct LinkedSection *ls,*maxls=NULL;
  struct Section *sec;
  unsigned long maxsize = 0;
  struct Symbol *sym;
  struct ObjectUnit *obj;

  if (gv->trace_file)
    fprintf(gv->trace_file,"\n");
  if (gv->map_file)
    fprintf(gv->map_file,"\n");

  for (ls=(struct LinkedSection *)gv->lnksec.first;
       ls->n.next!=NULL; ls=(struct LinkedSection *)ls->n.next) {
    bool print_symbols_of_header = TRUE;
    unsigned long lastsecend = 0;  /* for filling gaps */

    if (gv->trace_file) {
      if (!listempty(&ls->sections) && ls->size>0)
        fprintf(gv->trace_file,"Copying %s:\n",ls->name);
    }
    if (ls->size>maxsize || maxsize==0) {  /* finds largest section */
      maxsize = ls->size;
      maxls = ls;
    }
    /* allocate memory for section, even for uninitialized ones */
    ls->data = alloczero(ls->size);

    for (sec=(struct Section *)ls->sections.first;
         sec->n.next!=NULL; sec=(struct Section *)sec->n.next) {
      int i;

      if (ls->data && sec->data) {
        /* copy section contents, fill gaps */
        memset16(gv,ls->data + lastsecend,sec->filldata,
                 sec->offset - lastsecend);
        memcpy(ls->data+sec->offset,sec->data,sec->size);
        lastsecend = sec->offset + sec->size;
      }

      if (sec->obj) {
        /* find section symbols and fix their offsets */
        for (i=0; i<OBJSYMHTABSIZE; i++) {
          for (sym=sec->obj->objsyms[i]; sym; sym=sym->obj_chain) {
            if (sym->relsect == sec) {
#if 0
              if (sym->type==SYM_COMMON &&
                  (!gv->dest_object || gv->alloc_common)) {
                /* delete remaining copies of common symbols */
                remove_obj_symbol(sym);
              }
#endif
              if (!((sym->flags & (SYMF_REFERENCED|SYMF_PROVIDED))
                    == SYMF_PROVIDED)) { /* ignore unrefd. provided sym. */
                if (sym->type == SYM_RELOC)
                  sym->value += sec->va;  /* was sec->offset */
                addtail(&ls->symbols,&sym->n);

                if (gv->map_file) {
                  if (print_symbols_of_header)
                    fprintf(gv->map_file,"\nSymbols of %s:\n",ls->name);
                  print_symbol(gv->map_file,sym);
                  print_symbols_of_header = FALSE;
                }
              }
            }
          }
        }
      }
    }
  }

  if (gv->use_ldscript && maxls!=NULL) {
    /* put remaining absolute linker script symbols into the
       symbol list of the largest defined section: */
    if (gv->map_file)
      fprintf(gv->map_file,"\nLinker symbols:\n");
    while (sym = (struct Symbol *)remhead(&gv->scriptsymbols)) {
      if (!((sym->flags & (SYMF_REFERENCED|SYMF_PROVIDED))
            == SYMF_PROVIDED)) {
        sym->relsect = (struct Section *)maxls->sections.first;
        addtail(&maxls->symbols,&sym->n);
        if (gv->map_file)
          print_symbol(gv->map_file,sym);
      }
    }
  }

  /* last chance to fix linker symbols */
  fixlnksymbols(gv,maxls);

  /* fix offsets of relocatable debugging symbols */
  for (obj=(struct ObjectUnit *)gv->selobjects.first;
       obj->n.next!=NULL; obj=(struct ObjectUnit *)obj->n.next) {
    fixstabs(obj);
  }
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movq $0x0, 0x40(%rsp)
movq $0x0, 0x30(%rsp)
movq 0x50(%rsp), %rax
cmpq $0x0, 0xa0(%rax)
je 0xcd64
movq 0x50(%rsp), %rax
movq 0xa0(%rax), %rdi
leaq 0x2b609(%rip), %rsi     # 0x38366
movb $0x0, %al
callq 0x5150
movq 0x50(%rsp), %rax
cmpq $0x0, 0x90(%rax)
je 0xcd8d
movq 0x50(%rsp), %rax
movq 0x90(%rax), %rdi
leaq 0x2b5e0(%rip), %rsi     # 0x38366
movb $0x0, %al
callq 0x5150
movq 0x50(%rsp), %rax
movq 0x1c0(%rax), %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rax
cmpq $0x0, (%rax)
je 0xd05e
movl $0x1, 0x1c(%rsp)
movq $0x0, 0x10(%rsp)
movq 0x50(%rsp), %rax
cmpq $0x0, 0xa0(%rax)
je 0xce0d
movq 0x48(%rsp), %rax
movq 0x60(%rax), %rax
cmpq $0x0, (%rax)
je 0xce0b
movq 0x48(%rsp), %rax
cmpq $0x0, 0x48(%rax)
jbe 0xce0b
movq 0x50(%rsp), %rax
movq 0xa0(%rax), %rdi
movq 0x48(%rsp), %rax
movq 0x18(%rax), %rdx
leaq 0x2853f(%rip), %rsi     # 0x35343
movb $0x0, %al
callq 0x5150
jmp 0xce0d
movq 0x48(%rsp), %rax
movq 0x48(%rax), %rax
cmpq 0x30(%rsp), %rax
ja 0xce25
cmpq $0x0, 0x30(%rsp)
jne 0xce3d
movq 0x48(%rsp), %rax
movq 0x48(%rax), %rax
movq %rax, 0x30(%rsp)
movq 0x48(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x48(%rsp), %rax
movq 0x48(%rax), %rdi
callq 0x7290
movq %rax, %rcx
movq 0x48(%rsp), %rax
movq %rcx, 0x78(%rax)
movq 0x48(%rsp), %rax
movq 0x60(%rax), %rax
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rax
cmpq $0x0, (%rax)
je 0xd04a
movq 0x48(%rsp), %rax
cmpq $0x0, 0x78(%rax)
je 0xcf05
movq 0x38(%rsp), %rax
cmpq $0x0, 0x40(%rax)
je 0xcf05
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %rax
movq 0x78(%rax), %rsi
addq 0x10(%rsp), %rsi
movq 0x38(%rsp), %rax
movw 0x94(%rax), %ax
movq 0x38(%rsp), %rcx
movq 0x38(%rcx), %rcx
subq 0x10(%rsp), %rcx
movzwl %ax, %edx
callq 0x8930
movq 0x48(%rsp), %rax
movq 0x78(%rax), %rdi
movq 0x38(%rsp), %rax
addq 0x38(%rax), %rdi
movq 0x38(%rsp), %rax
movq 0x40(%rax), %rsi
movq 0x38(%rsp), %rax
movq 0x48(%rax), %rdx
callq 0x5170
movq 0x38(%rsp), %rax
movq 0x38(%rax), %rax
movq 0x38(%rsp), %rcx
addq 0x48(%rcx), %rax
movq %rax, 0x10(%rsp)
movq 0x38(%rsp), %rax
cmpq $0x0, 0x10(%rax)
je 0xd036
movl $0x0, 0xc(%rsp)
cmpl $0x20, 0xc(%rsp)
jge 0xd034
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x48(%rax), %rax
movslq 0xc(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x28(%rsp)
je 0xd022
movq 0x28(%rsp), %rax
movq 0x38(%rax), %rax
cmpq 0x38(%rsp), %rax
jne 0xd00d
movq 0x28(%rsp), %rax
movzbl 0x41(%rax), %eax
andl $0xa, %eax
cmpl $0x8, %eax
je 0xd00b
movq 0x28(%rsp), %rax
movzbl 0x40(%rax), %eax
cmpl $0x2, %eax
jne 0xcf9c
movq 0x38(%rsp), %rax
movq 0x30(%rax), %rcx
movq 0x28(%rsp), %rax
addq 0x30(%rax), %rcx
movq %rcx, 0x30(%rax)
movq 0x48(%rsp), %rdi
addq $0xb0, %rdi
movq 0x28(%rsp), %rsi
callq 0x7470
movq 0x50(%rsp), %rax
cmpq $0x0, 0x90(%rax)
je 0xd009
cmpl $0x0, 0x1c(%rsp)
je 0xcfeb
movq 0x50(%rsp), %rax
movq 0x90(%rax), %rdi
movq 0x48(%rsp), %rax
movq 0x18(%rax), %rdx
leaq 0x2836c(%rip), %rsi     # 0x35350
movb $0x0, %al
callq 0x5150
movq 0x50(%rsp), %rax
movq 0x90(%rax), %rdi
movq 0x28(%rsp), %rsi
callq 0x9190
movl $0x0, 0x1c(%rsp)
jmp 0xd00b
jmp 0xd00d
jmp 0xd00f
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x28(%rsp)
jmp 0xcf43
jmp 0xd024
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0xcf1d
jmp 0xd036
jmp 0xd038
movq 0x38(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x38(%rsp)
jmp 0xce65
jmp 0xd04c
movq 0x48(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x48(%rsp)
jmp 0xcd9e
movq 0x50(%rsp), %rax
cmpl $0x0, 0x244(%rax)
je 0xd127
cmpq $0x0, 0x40(%rsp)
je 0xd127
movq 0x50(%rsp), %rax
cmpq $0x0, 0x90(%rax)
je 0xd0a5
movq 0x50(%rsp), %rax
movq 0x90(%rax), %rdi
leaq 0x282c3(%rip), %rsi     # 0x35361
movb $0x0, %al
callq 0x5150
jmp 0xd0a7
movq 0x50(%rsp), %rdi
addq $0x190, %rdi            # imm = 0x190
callq 0x74d0
movq %rax, 0x28(%rsp)
cmpq $0x0, %rax
je 0xd125
movq 0x28(%rsp), %rax
movzbl 0x41(%rax), %eax
andl $0xa, %eax
cmpl $0x8, %eax
je 0xd123
movq 0x40(%rsp), %rax
movq 0x60(%rax), %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x38(%rax)
movq 0x40(%rsp), %rdi
addq $0xb0, %rdi
movq 0x28(%rsp), %rsi
callq 0x7470
movq 0x50(%rsp), %rax
cmpq $0x0, 0x90(%rax)
je 0xd121
movq 0x50(%rsp), %rax
movq 0x90(%rax), %rdi
movq 0x28(%rsp), %rsi
callq 0x9190
jmp 0xd123
jmp 0xd0a7
jmp 0xd127
movq 0x50(%rsp), %rdi
movq 0x40(%rsp), %rsi
callq 0x103f0
movq 0x50(%rsp), %rax
movq 0x138(%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
cmpq $0x0, (%rax)
je 0xd16b
movq 0x20(%rsp), %rdi
callq 0x10cc0
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x20(%rsp)
jmp 0xd147
addq $0x58, %rsp
retq