// File: /workspace/github_c_makefile_star2_O3/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 $0x28, %rsp
movq %rdi, %rbx
movq 0xa0(%rdi), %rsi
testq %rsi, %rsi
je 0x9309
movl $0xa, %edi
callq 0x5150
movq 0x90(%rbx), %rsi
testq %rsi, %rsi
je 0x931f
movl $0xa, %edi
callq 0x5150
movq 0x1c0(%rbx), %r12
cmpq $0x0, (%r12)
je 0x956e
xorl %r15d, %r15d
xorl %r14d, %r14d
movq 0xa0(%rbx), %rdi
testq %rdi, %rdi
je 0x9369
movq 0x60(%r12), %rax
cmpq $0x0, (%rax)
je 0x9369
cmpq $0x0, 0x48(%r12)
je 0x9369
movq 0x18(%r12), %rdx
leaq 0x18fe9(%rip), %rsi     # 0x2234b
xorl %eax, %eax
callq 0x5180
movq 0x48(%r12), %rdi
cmpq %r15, %rdi
seta %al
testq %r15, %r15
sete %cl
orb %al, %cl
cmovneq %r12, %r14
movq %r14, 0x20(%rsp)
cmovneq %rdi, %r15
movq %r15, 0x18(%rsp)
callq 0x6686
movq %rax, 0x78(%r12)
movq 0x60(%r12), %r14
cmpq $0x0, (%r14)
je 0x94bc
leaq 0xb0(%r12), %r13
movl $0x1, %r15d
movq $0x0, 0x8(%rsp)
movq %r12, 0x10(%rsp)
movq 0x78(%r12), %rsi
testq %rsi, %rsi
je 0x9416
cmpq $0x0, 0x40(%r14)
je 0x9416
movq 0x8(%rsp), %rax
addq %rax, %rsi
movzwl 0x94(%r14), %edx
movq 0x38(%r14), %rcx
subq %rax, %rcx
movq %rbx, %rdi
callq 0x6e53
movq 0x78(%r12), %rdi
addq 0x38(%r14), %rdi
movq 0x40(%r14), %rsi
movq 0x48(%r14), %rdx
callq 0x51a0
movq 0x48(%r14), %rax
addq 0x38(%r14), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, 0x10(%r14)
je 0x94aa
xorl %r12d, %r12d
movq 0x10(%r14), %rax
movq 0x48(%rax), %rax
movq (%rax,%r12,8), %rbp
testq %rbp, %rbp
je 0x949d
cmpq %r14, 0x38(%rbp)
jne 0x9497
movb 0x41(%rbp), %al
andb $0xa, %al
cmpb $0x8, %al
je 0x9497
cmpb $0x2, 0x40(%rbp)
jne 0x9452
movq 0x30(%r14), %rax
addq %rax, 0x30(%rbp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x6729
movq 0x90(%rbx), %rdi
testq %rdi, %rdi
je 0x9497
testl %r15d, %r15d
je 0x948c
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rdx
leaq 0x18eda(%rip), %rsi     # 0x22358
xorl %eax, %eax
callq 0x5180
movq 0x90(%rbx), %rdi
movq %rbp, %rsi
callq 0x7225
xorl %r15d, %r15d
movq 0x18(%rbp), %rbp
jmp 0x9430
incq %r12
cmpq $0x20, %r12
jne 0x9424
movq (%r14), %r14
cmpq $0x0, (%r14)
movq 0x10(%rsp), %r12
jne 0x93c3
movq (%r12), %r12
cmpq $0x0, (%r12)
movq 0x20(%rsp), %r14
movq 0x18(%rsp), %r15
jne 0x9337
cmpl $0x0, 0x244(%rbx)
je 0x9571
testq %r14, %r14
je 0x9571
movq 0x90(%rbx), %rcx
testq %rcx, %rcx
je 0x950d
leaq 0x18e6b(%rip), %rdi     # 0x22369
movl $0x11, %esi
movl $0x1, %edx
callq 0x5270
leaq 0x190(%rbx), %r15
movq %r15, %rdi
callq 0x673f
testq %rax, %rax
je 0x9571
movq %rax, %r13
leaq 0xb0(%r14), %r12
movb 0x41(%r13), %al
andb $0xa, %al
cmpb $0x8, %al
je 0x955c
movq 0x60(%r14), %rax
movq %rax, 0x38(%r13)
movq %r12, %rdi
movq %r13, %rsi
callq 0x6729
movq 0x90(%rbx), %rdi
testq %rdi, %rdi
je 0x955c
movq %r13, %rsi
callq 0x7225
movq %r15, %rdi
callq 0x673f
movq %rax, %r13
testq %rax, %rax
jne 0x952b
jmp 0x9571
xorl %r14d, %r14d
movq %rbx, %rdi
movq %r14, %rsi
callq 0xaea0
movq 0x138(%rbx), %rbx
cmpq $0x0, (%rbx)
je 0x9596
movq %rbx, %rdi
callq 0xb343
movq (%rbx), %rbx
jmp 0x9583
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq