// File: /workspace/github_c_makefile_star2_O3/deplinenoise[P]vlink/t_elf32.c
// Function: elf32_symbols
void elf32_symbols(struct GlobalVars *gv,struct Elf32_Ehdr *ehdr,
                   struct ObjectUnit *ou,struct Elf32_Shdr *shdr)
/* convert ELF symbol definitions into internal format */
{
  bool be = (ehdr->e_ident[EI_DATA] == ELFDATA2MSB);
  uint8_t flags = (read32(be,shdr->sh_type)==SHT_DYNSYM) ? SYMF_SHLIB : 0;
  struct LinkFile *lf = ou->lnkfile;
  uint8_t *data = (uint8_t *)ehdr + read32(be,shdr->sh_offset);
  unsigned long entsize = read32(be,shdr->sh_entsize);
  int nsyms = (int)(read32(be,shdr->sh_size) / (uint32_t)entsize);
  char *strtab = elf32_strtab(lf,ehdr,read32(be,shdr->sh_link));
  struct Section *sec;
  struct Elf32_Sym *elfsym;

  if ((data < lf->data) || 
      (data + read32(be,shdr->sh_size) > lf->data + lf->length))
    error(51,lf->pathname,"symbol",lf->objname);  /* illegal offset */

  /* read ELF xdef symbols and convert to internal format */
  while (--nsyms > 0) {
    int shndx;
    char *symname;
    uint8_t type=0;
    uint8_t objinfo,objbind;

    elfsym = (struct Elf32_Sym *)(data += entsize);
    symname = strtab + read32(be,elfsym->st_name);
    if (symname<(char *)lf->data || symname>(char *)lf->data+lf->length)
      error(127,lf->pathname,read32(be,elfsym->st_name),lf->objname);

    if (flags & SYMF_SHLIB) {
      /* don't import linker symbols from shared objects - we make our own */
      int i;

      for (i=0; i<(sizeof(elf32_symnames)/sizeof(elf32_symnames[0])); i++) {
        if (!strcmp(elf32_symnames[i],symname)) {
          symname = NULL;
          break;
        }
      }
      if (!symname)
        continue;
    }

    switch (shndx = (int)read16(be,elfsym->st_shndx)) {
      case SHN_UNDEF:
        sec = NULL;  /* ignore xrefs for now */
        break;
      /* assign a section for ABS and COMMON symbols */
      case SHN_ABS:
        sec = abs_section(ou);
        type = SYM_ABS;
        break;
      case SHN_COMMON:
        sec = common_section(gv,ou);
        type = SYM_COMMON;
        break;
      /* reloc symbols have a definite section to which they belong */
      default:
        if (read32(be,shdr->sh_type) == SHT_DYNSYM) {
          /* just put dynamic symbols into the first section -
             the section index might be wrong in .dynsym */
          sec = abs_section(ou);
        }
        else if (!(sec = find_sect_id(ou,shndx))) {
          /* a section with this index doesn't exist! */
          if (ELF32_ST_TYPE(*elfsym->st_info) != STT_SECTION)
            error(53,lf->pathname,symname,lf->objname,shndx);
        }
        type = SYM_RELOC;
        break;
    }

    if ((objinfo = ELF32_ST_TYPE(*elfsym->st_info)) == STT_SECTION)
      sec = NULL;  /* ignore section defines - will be reproduced */

    if (sec) {
      if (objinfo > STT_FILE) {
        /* illegal symbol type */
        error(54,lf->pathname,(int)objinfo,symname,lf->objname);
        objinfo = STT_NOTYPE;
      }
      switch (ELF32_ST_BIND(*elfsym->st_info)) {
        case STB_LOCAL:
          objbind = SYMB_LOCAL;
          break;
        case STB_GLOBAL:
          objbind = SYMB_GLOBAL;
          break;
        case STB_WEAK:
          objbind = SYMB_WEAK;
          break;
        default:  /* illegal binding type */
          error(55,lf->pathname,symname,ELF32_ST_BIND(*elfsym->st_info),
                lf->objname);
          objbind = SYMB_LOCAL;
          break;
      }

      /* add a new symbol definition */
      if (objbind == SYMB_LOCAL) {
        addlocsymbol(gv,sec,symname,NULL,(int32_t)read32(be,elfsym->st_value),
                     type,flags,objinfo,read32(be,elfsym->st_size));
      }
      else {
        addsymbol(gv,sec,symname,NULL,(int32_t)read32(be,elfsym->st_value),
                  type,flags,objinfo,objbind,read32(be,elfsym->st_size),TRUE);
      }
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, 0x30(%rsp)
xorl %ebp, %ebp
cmpb $0x2, 0x5(%rsi)
sete %bpl
leaq 0x4(%rcx), %rsi
movl %ebp, %edi
movq %rsi, 0x58(%rsp)
callq 0x696f
movl %eax, 0x44(%rsp)
cmpl $0xb, %eax
sete 0x20(%rsp)
movq %r14, 0x28(%rsp)
movq 0x10(%r14), %r13
leaq 0x10(%rbx), %rsi
movl %ebp, %edi
callq 0x696f
movl %eax, %r15d
addq %r12, %r15
leaq 0x24(%rbx), %rsi
movl %ebp, %edi
callq 0x696f
movl %eax, %r14d
leaq 0x14(%rbx), %rsi
movl %ebp, %edi
movq %rsi, 0x18(%rsp)
callq 0x696f
xorl %edx, %edx
movl %r14d, 0x38(%rsp)
divl %r14d
movl %eax, %r14d
addq $0x18, %rbx
movl %ebp, 0x8(%rsp)
movl %ebp, %edi
movq %rbx, %rsi
callq 0x696f
movq %r13, %rdi
movq %r12, %rsi
movl %eax, %edx
callq 0x141f2
movq %rax, 0x50(%rsp)
cmpq 0x28(%r13), %r15
jb 0x1461f
movl 0x8(%rsp), %edi
movq 0x18(%rsp), %rsi
callq 0x696f
movl %eax, %eax
addq %r15, %rax
movq 0x28(%r13), %rcx
addq 0x30(%r13), %rcx
cmpq %rcx, %rax
jbe 0x1463a
movq 0x10(%r13), %rsi
movq 0x20(%r13), %rcx
leaq 0xd0d6(%rip), %rdx      # 0x21704
movl $0x33, %edi
xorl %eax, %eax
callq 0x6f14
cmpl $0x2, %r14d
jl 0x148d6
movl 0x38(%rsp), %eax
movq %rax, 0x38(%rsp)
movb 0x20(%rsp), %al
shlb $0x4, %al
leaq 0x1b1c5(%rip), %rbp     # 0x2f820
movzbl %al, %eax
movq %rax, 0x48(%rsp)
addq 0x38(%rsp), %r15
movl 0x8(%rsp), %edi
movq %r15, %rsi
callq 0x696f
movl %eax, %r12d
addq 0x50(%rsp), %r12
movq 0x28(%r13), %rax
cmpq %rax, %r12
jb 0x1468e
addq 0x30(%r13), %rax
cmpq %rax, %r12
jbe 0x146b3
movq 0x10(%r13), %rbx
movl 0x8(%rsp), %edi
movq %r15, %rsi
callq 0x696f
movq 0x20(%r13), %rcx
movl $0x7f, %edi
movq %rbx, %rsi
movl %eax, %edx
xorl %eax, %eax
callq 0x6f14
cmpl $0xb, 0x44(%rsp)
jne 0x146e6
xorl %ebx, %ebx
movq (%rbx,%rbp), %rdi
movq %r12, %rsi
callq 0x5160
testl %eax, %eax
je 0x1489d
addq $0x8, %rbx
cmpq $0x38, %rbx
jne 0x146bc
cmpq $0x0, 0x50(%rsp)
je 0x1489d
leaq 0xe(%r15), %rsi
movl 0x8(%rsp), %edi
callq 0x695f
testw %ax, %ax
je 0x1489d
movzwl %ax, %ebx
cmpl $0xfff2, %ebx           # imm = 0xFFF2
je 0x1471d
cmpl $0xfff1, %ebx           # imm = 0xFFF1
jne 0x14730
movq 0x28(%rsp), %rdi
callq 0xc25f
movb $0x1, %bl
jmp 0x14766
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0xc195
movb $0x3, %bl
jmp 0x14766
movl 0x8(%rsp), %edi
movq 0x58(%rsp), %rsi
callq 0x696f
cmpl $0xb, %eax
jne 0x1474f
movq 0x28(%rsp), %rdi
callq 0xc25f
jmp 0x14764
movq 0x28(%rsp), %rdi
movl %ebx, %esi
callq 0xbdad
testq %rax, %rax
je 0x148b0
movb $0x2, %bl
movzbl 0xc(%r15), %ecx
movl %ecx, %edx
andl $0xf, %edx
cmpl $0x3, %edx
je 0x1489d
testq %rax, %rax
je 0x1489d
movq %rax, 0x20(%rsp)
cmpb $0x5, %dl
jb 0x147a9
movq 0x10(%r13), %rsi
movq 0x20(%r13), %r8
movl $0x36, %edi
movq %r12, %rcx
xorl %eax, %eax
callq 0x6f14
movb 0xc(%r15), %cl
xorl %edx, %edx
shrb $0x4, %cl
movzbl %dl, %eax
movq %rax, 0x18(%rsp)
movzbl %bl, %eax
movl %eax, 0xc(%rsp)
je 0x1484d
movzbl %cl, %ecx
cmpl $0x1, %ecx
je 0x147d5
cmpl $0x2, %ecx
jne 0x14836
movb $0x3, 0x10(%rsp)
jmp 0x147da
movb $0x2, 0x10(%rsp)
leaq 0x4(%r15), %rsi
movl 0x8(%rsp), %ebx
movl %ebx, %edi
callq 0x696f
cltq
movq %rax, 0x60(%rsp)
leaq 0x8(%r15), %rsi
movl %ebx, %edi
callq 0x696f
subq $0x8, %rsp
movzbl 0x18(%rsp), %r10d
movq 0x38(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq %r12, %rdx
xorl %ecx, %ecx
movq 0x68(%rsp), %r8
movl 0x14(%rsp), %r9d
pushq $0x1
pushq %rax
pushq %r10
pushq 0x38(%rsp)
pushq 0x70(%rsp)
callq 0xaad4
addq $0x30, %rsp
jmp 0x1489d
movq 0x10(%r13), %rsi
movq 0x20(%r13), %r8
movl $0x37, %edi
movq %r12, %rdx
xorl %eax, %eax
callq 0x6f14
leaq 0x4(%r15), %rsi
movl 0x8(%rsp), %ebx
movl %ebx, %edi
callq 0x696f
cltq
movq %rax, 0x10(%rsp)
leaq 0x8(%r15), %rsi
movl %ebx, %edi
callq 0x696f
subq $0x8, %rsp
movq 0x38(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq %r12, %rdx
xorl %ecx, %ecx
movq 0x18(%rsp), %r8
movl 0x14(%rsp), %r9d
pushq %rax
pushq 0x28(%rsp)
pushq 0x60(%rsp)
callq 0xacd9
addq $0x20, %rsp
leal -0x1(%r14), %eax
cmpl $0x2, %r14d
movl %eax, %r14d
jg 0x14663
jmp 0x148d6
movb 0xc(%r15), %al
andb $0xf, %al
cmpb $0x3, %al
je 0x1489d
movq 0x10(%r13), %rsi
movq 0x20(%r13), %rcx
movl $0x35, %edi
movq %r12, %rdx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x6f14
jmp 0x1489d
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq