// File: /workspace/github_c_makefile_star2_O1/deplinenoise[P]vlink/targets.c
// Function: reenter_global_objsyms
void reenter_global_objsyms(struct GlobalVars *gv,struct ObjectUnit *ou)
/* Check all global symbols of an object unit against the global symbol
   table for redefinitions or common symbols.
   This is required when a new unit has been pulled into the linking
   process to resolve an undefined reference. */
{
  int i;

  for (i=0; i<OBJSYMHTABSIZE; i++) {
    struct Symbol *sym = ou->objsyms[i];

    while (sym) {
      if (sym->bind==SYMB_GLOBAL) {
        struct Symbol **chain = &gv->symbols[elf_hash(sym->name)%SYMHTABSIZE];
        struct Symbol *gsym;

        while (gsym = *chain) {
          if (!strcmp(sym->name,gsym->name))
            break;
          chain = &gsym->glob_chain;
        }

        if (gsym!=NULL && gsym!=sym) {
          if (sym->type==SYM_COMMON && gsym->type==SYM_COMMON) {
            if ((sym->size>gsym->size && sym->value>=gsym->value) ||
                (sym->size>=gsym->size && sym->value>gsym->value)) {
              /* replace by common symbol with bigger size or alignment */
              sym->glob_chain = gsym->glob_chain;
              remove_obj_symbol(gsym);  /* delete old symbol in object unit */
              *chain = sym;
            }
          }
          else {
            if (ou->lnkfile->type < ID_SHAREDOBJ)  {
              /* Global symbol "x" is already defined in... */
              error(19,ou->lnkfile->pathname,sym->name,getobjname(ou),
                    getobjname(gsym->relsect->obj));
            }
            #if 0
            /* This causes problems when using the same symbols for different
               CPUs, as with WarpOS/68k mixed-binaries (target amigaehf) */
            else {
              /* hide library symbol by replacing its name by:
                 __<object unit name>__<symbol name> */
              char buf[10];
              char *oname,*newname;

              if (ou->objname == NULL) {
                sprintf(buf,"o%08lx",(unsigned long)ou);
                oname = buf;
              }
              else
                oname = ou->objname;
              newname = alloc(strlen(oname) + strlen(sym->name) + 5);
              sprintf(newname,"__%s__%s",oname,sym->name);
              sym->name = newname;
            }
            #endif
          }
        }
      }
      sym = sym->obj_chain;
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, 0x8(%rsp)
movq %rdi, %r14
xorl %ecx, %ecx
movq 0x8(%rsp), %rax
movq 0x48(%rax), %rax
movq %rcx, 0x10(%rsp)
movq (%rax,%rcx,8), %rbx
testq %rbx, %rbx
je 0xb1e1
cmpb $0x2, 0x43(%rbx)
jne 0xb1d8
movq 0x180(%r14), %r13
movq 0x20(%rbx), %rdi
callq 0x6e09
movzwl %ax, %ebp
movq (%r13,%rbp,8), %r15
testq %r15, %r15
je 0xb1d8
movq 0x20(%rbx), %r12
movq 0x20(%r15), %rsi
movq %r12, %rdi
callq 0x5160
testl %eax, %eax
je 0xb137
movq %r15, %r13
movq 0x10(%r15), %r15
testq %r15, %r15
je 0xb1d8
movq 0x20(%r15), %rsi
movq %r12, %rdi
callq 0x5160
testl %eax, %eax
jne 0xb111
addq $0x10, %r13
jmp 0xb13c
leaq (%r13,%rbp,8), %r13
cmpq %rbx, %r15
je 0xb1d8
cmpb $0x3, 0x40(%rbx)
jne 0xb193
cmpb $0x3, 0x40(%r15)
jne 0xb193
movl 0x44(%rbx), %eax
movl 0x44(%r15), %ecx
cmpl %ecx, %eax
jbe 0xb167
movq 0x30(%rbx), %rdx
cmpq 0x30(%r15), %rdx
jge 0xb175
cmpl %ecx, %eax
jb 0xb1d8
movq 0x30(%rbx), %rax
cmpq 0x30(%r15), %rax
jle 0xb1d8
movq 0x10(%r15), %rax
movq %rax, 0x10(%rbx)
movq %r15, %rdi
callq 0xcddb
movq %r15, %rdi
callq 0x5040
movq %rbx, (%r13)
jmp 0xb1d8
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
cmpb $0x3, 0x39(%rax)
ja 0xb1d8
movq 0x10(%rax), %r13
movq 0x8(%rsp), %rdi
callq 0x7174
movq %rax, %rbp
movq 0x38(%r15), %rax
movq 0x10(%rax), %rdi
callq 0x7174
movl $0x13, %edi
movq %r13, %rsi
movq %r12, %rdx
movq %rbp, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x6f84
movq 0x18(%rbx), %rbx
jmp 0xb0c9
movq 0x10(%rsp), %rcx
incq %rcx
cmpq $0x20, %rcx
jne 0xb0b7
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq