// File: /workspace/github_c_makefile_star2_O2/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 $0x58, %rsp
movq %rcx, %r12
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, 0x20(%rsp)
xorl %ebp, %ebp
cmpb $0x2, 0x5(%rsi)
sete %bpl
leaq 0x4(%rcx), %rsi
movl %ebp, %edi
movq %rsi, 0x48(%rsp)
callq 0x664d
movl %eax, 0x2c(%rsp)
cmpl $0xb, %eax
sete %al
shlb $0x4, %al
movb %al, 0x4(%rsp)
movq %r14, 0x18(%rsp)
movq 0x10(%r14), %r13
leaq 0x10(%r12), %rsi
movl %ebp, %edi
callq 0x664d
movl %eax, %r15d
addq %rbx, %r15
leaq 0x24(%r12), %rsi
movl %ebp, %edi
callq 0x664d
movl %eax, %r14d
movl %eax, %eax
movq %rax, 0x50(%rsp)
leaq 0x14(%r12), %rsi
movl %ebp, %edi
movq %rsi, 0x8(%rsp)
callq 0x664d
xorl %edx, %edx
divl %r14d
movl %ebp, %r14d
movl %eax, 0x14(%rsp)
addq $0x18, %r12
movl %ebp, %edi
movq %r12, %rsi
callq 0x664d
movq %r13, %rdi
movq %rbx, %rsi
movl %eax, %edx
callq 0x13102
movq %rax, 0x40(%rsp)
cmpq 0x28(%r13), %r15
jb 0x13526
movl %r14d, %edi
movq 0x8(%rsp), %rsi
callq 0x664d
movl %eax, %eax
addq %r15, %rax
movq 0x28(%r13), %rcx
addq 0x30(%r13), %rcx
cmpq %rcx, %rax
jbe 0x1353f
movq 0x10(%r13), %rsi
movq 0x20(%r13), %rcx
leaq 0xc1cf(%rip), %rdx      # 0x1f704
pushq $0x33
popq %rdi
xorl %eax, %eax
callq 0x6c19
movq %r13, 0x8(%rsp)
leaq 0x1c2e5(%rip), %rbp     # 0x2f830
movzbl 0x4(%rsp), %eax
movq %rax, 0x30(%rsp)
movl %r14d, 0x4(%rsp)
cmpl $0x2, 0x14(%rsp)
jl 0x137ec
addq 0x50(%rsp), %r15
movl %r14d, %edi
movq %r15, %rsi
callq 0x664d
movl %eax, %r12d
addq 0x40(%rsp), %r12
movq 0x8(%rsp), %r13
movq 0x28(%r13), %rax
cmpq %rax, %r12
jb 0x13594
addq 0x30(%r13), %rax
cmpq %rax, %r12
jbe 0x135b6
movq 0x10(%r13), %rbx
movl %r14d, %edi
movq %r15, %rsi
callq 0x664d
movq 0x20(%r13), %rcx
pushq $0x7f
popq %rdi
movq %rbx, %rsi
movl %eax, %edx
xorl %eax, %eax
callq 0x6c19
decl 0x14(%rsp)
cmpl $0xb, 0x2c(%rsp)
jne 0x135ee
xorl %ebx, %ebx
cmpq $0x38, %rbx
je 0x135e2
movq (%rbx,%rbp), %rdi
movq %r12, %rsi
callq 0x5160
addq $0x8, %rbx
testl %eax, %eax
jne 0x135c3
jmp 0x1355a
cmpq $0x0, 0x40(%rsp)
je 0x1355a
leaq 0xe(%r15), %rsi
movl %r14d, %edi
callq 0x663d
testw %ax, %ax
je 0x13641
movzwl %ax, %r14d
cmpl $0xfff2, %r14d          # imm = 0xFFF2
je 0x1362a
cmpl $0xfff1, %r14d          # imm = 0xFFF1
jne 0x13648
movq 0x18(%rsp), %rdi
callq 0xbbcd
movq %rax, %rbx
movb $0x1, %r13b
jmp 0x136b0
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0xbb2a
movq %rax, %rbx
movb $0x3, %r13b
jmp 0x136b0
xorl %ebx, %ebx
xorl %r13d, %r13d
jmp 0x136b5
movl 0x4(%rsp), %edi
movq 0x48(%rsp), %rsi
callq 0x664d
cmpl $0xb, %eax
jne 0x1366d
movq 0x18(%rsp), %rdi
callq 0xbbcd
movq %rax, %rbx
movb $0x2, %r13b
jmp 0x136b0
movq 0x18(%rsp), %rdi
movl %r14d, %esi
callq 0xb783
movb $0x2, %r13b
testq %rax, %rax
je 0x13687
movq %rax, %rbx
jmp 0x136b0
movb 0xc(%r15), %al
andb $0xf, %al
cmpb $0x3, %al
je 0x136ae
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rsi
movq 0x20(%rax), %rcx
pushq $0x35
popq %rdi
movq %r12, %rdx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x6c19
xorl %ebx, %ebx
movl 0x4(%rsp), %r14d
movzbl 0xc(%r15), %eax
movl %eax, %edx
andl $0xf, %edx
cmpl $0x3, %edx
je 0x1355a
testq %rbx, %rbx
je 0x1355a
cmpb $0x5, %dl
jb 0x136f6
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rsi
movq 0x20(%rax), %r8
pushq $0x36
popq %rdi
movq %r12, %rcx
xorl %eax, %eax
callq 0x6c19
movb 0xc(%r15), %al
xorl %edx, %edx
shrb $0x4, %al
movzbl %dl, %ecx
movq %rcx, 0x38(%rsp)
movzbl %r13b, %r13d
je 0x1379d
movzbl %al, %ecx
cmpl $0x1, %ecx
je 0x13722
cmpl $0x2, %ecx
jne 0x13783
movl %r13d, 0x10(%rsp)
movb $0x3, %r13b
jmp 0x1372a
movl %r13d, 0x10(%rsp)
movb $0x2, %r13b
leaq 0x4(%r15), %rsi
movl %r14d, %edi
callq 0x664d
movslq %eax, %r14
leaq 0x8(%r15), %rsi
movl 0x4(%rsp), %edi
callq 0x664d
subq $0x8, %rsp
movzbl %r13b, %r10d
movq 0x28(%rsp), %rdi
movq %rbx, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
movq %r14, %r8
movl 0xc(%rsp), %r14d
movl 0x18(%rsp), %r9d
pushq $0x1
pushq %rax
pushq %r10
pushq 0x58(%rsp)
pushq 0x58(%rsp)
callq 0xa5d5
addq $0x30, %rsp
jmp 0x1355a
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rsi
movq 0x20(%rax), %r8
pushq $0x37
popq %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x6c19
leaq 0x4(%r15), %rsi
movl %r14d, %edi
callq 0x664d
movslq %eax, %r14
leaq 0x8(%r15), %rsi
movl 0x4(%rsp), %edi
callq 0x664d
subq $0x8, %rsp
movq 0x28(%rsp), %rdi
movq %rbx, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
movq %r14, %r8
movl 0xc(%rsp), %r14d
movl %r13d, %r9d
pushq %rax
pushq 0x48(%rsp)
pushq 0x48(%rsp)
callq 0xa7c3
addq $0x20, %rsp
jmp 0x1355a
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq