// File: /workspace/github_c_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
movq 0xa0(%rdi), %rsi
testq %rsi, %rsi
je 0x8de9
pushq $0xa
popq %rdi
callq 0x5150
movq 0x90(%rbx), %rsi
testq %rsi, %rsi
je 0x8dfd
pushq $0xa
popq %rdi
callq 0x5150
leaq 0x1c0(%rbx), %r12
xorl %r14d, %r14d
xorl %r15d, %r15d
movq (%r12), %r12
cmpq $0x0, (%r12)
je 0x8fcb
movq %rbx, %rbp
movq 0xa0(%rbx), %rdi
testq %rdi, %rdi
je 0x8e4e
movq 0x60(%r12), %rax
cmpq $0x0, (%rax)
je 0x8e4e
cmpq $0x0, 0x48(%r12)
je 0x8e4e
movq 0x18(%r12), %rdx
leaq 0x17514(%rip), %rsi     # 0x2035b
xorl %eax, %eax
callq 0x5180
movq 0x48(%r12), %rdi
cmpq %r15, %rdi
seta %al
movq %r15, 0x28(%rsp)
testq %r15, %r15
sete %cl
orb %al, %cl
movb %cl, 0xf(%rsp)
cmovneq %r12, %r14
movq %rdi, 0x20(%rsp)
callq 0x638a
movq %rax, 0x78(%r12)
leaq 0x60(%r12), %r13
leaq 0xb0(%r12), %rax
movq %rax, 0x30(%rsp)
pushq $0x1
popq %r15
movq $0x0, 0x10(%rsp)
movq (%r13), %r13
cmpq $0x0, (%r13)
je 0x8fb3
movq 0x78(%r12), %rsi
testq %rsi, %rsi
je 0x8efe
cmpq $0x0, 0x40(%r13)
je 0x8efe
movq 0x10(%rsp), %rax
addq %rax, %rsi
movzwl 0x94(%r13), %edx
movq 0x38(%r13), %rcx
subq %rax, %rcx
movq %rbp, %rdi
callq 0x6a84
movq 0x78(%r12), %rdi
addq 0x38(%r13), %rdi
movq 0x40(%r13), %rsi
movq 0x48(%r13), %rdx
callq 0x51a0
movq 0x48(%r13), %rax
addq 0x38(%r13), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%r13)
je 0x8e9c
movq %r14, 0x18(%rsp)
xorl %r14d, %r14d
cmpq $0x20, %r14
je 0x8fa9
movq %r12, %rbx
movq 0x10(%r13), %rax
leaq (,%r14,8), %r12
addq 0x48(%rax), %r12
movq (%r12), %r12
testq %r12, %r12
je 0x8f9e
cmpq %r13, 0x38(%r12)
jne 0x8f98
movb 0x41(%r12), %al
andb $0xa, %al
cmpb $0x8, %al
je 0x8f98
cmpb $0x2, 0x40(%r12)
jne 0x8f56
movq 0x30(%r13), %rax
addq %rax, 0x30(%r12)
movq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0x6414
movq 0x90(%rbp), %rdi
testq %rdi, %rdi
je 0x8f98
testl %r15d, %r15d
je 0x8f8d
movq 0x18(%rbx), %rdx
leaq 0x173e9(%rip), %rsi     # 0x20368
xorl %eax, %eax
callq 0x5180
movq 0x90(%rbp), %rdi
movq %r12, %rsi
callq 0x6f81
xorl %r15d, %r15d
addq $0x18, %r12
jmp 0x8f2a
incq %r14
movq %rbx, %r12
jmp 0x8f0d
movq 0x18(%rsp), %r14
jmp 0x8e9c
cmpb $0x0, 0xf(%rsp)
movq 0x28(%rsp), %r15
cmovneq 0x20(%rsp), %r15
movq %rbp, %rbx
jmp 0x8e0a
cmpl $0x0, 0x244(%rbx)
je 0x9047
testq %r14, %r14
je 0x9047
movq 0x90(%rbx), %rcx
testq %rcx, %rcx
je 0x8ff7
leaq 0x1738d(%rip), %rdi     # 0x20379
pushq $0x11
popq %rsi
pushq $0x1
popq %rdx
callq 0x5280
leaq 0x190(%rbx), %r15
leaq 0xb0(%r14), %r12
movq %r15, %rdi
callq 0x642a
testq %rax, %rax
je 0x9047
movq %rax, %r13
movb 0x41(%rax), %al
andb $0xa, %al
cmpb $0x8, %al
je 0x9005
movq 0x60(%r14), %rax
movq %rax, 0x38(%r13)
movq %r12, %rdi
movq %r13, %rsi
callq 0x6414
movq 0x90(%rbx), %rdi
testq %rdi, %rdi
je 0x9005
movq %r13, %rsi
callq 0x6f81
jmp 0x9005
movq %rbx, %rdi
movq %r14, %rsi
callq 0xa970
addq $0x138, %rbx            # imm = 0x138
movq (%rbx), %rbx
cmpq $0x0, (%rbx)
je 0x906c
movq %rbx, %rdi
callq 0xade5
jmp 0x9059
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq