// File: /workspace/github_c_makefile_star2_O3/deplinenoise[P]vlink/t_elf32.c
// Function: elf32_dyncreate
void elf32_dyncreate(struct GlobalVars *gv,const char *pltgot_name)
/* generate .hash, populate .dynstr and .dynamic, allocate .dynsym,
   so that all sections have a valid size for the address calculation */
{
  const char *fn = "elf32_bssentry():";
  struct Section *dynstr,*dynsym,*pltgot;
  struct LibPath *lpn;

  if (gv->dynobj == NULL)
    ierror("%s no dynobj",fn);

  /* write SONAME and RPATHs */
  if (gv->soname && gv->dest_sharedobj)
    elf32_dynamicentry(gv,DT_SONAME,elf32_adddynstr(gv->soname),NULL);
  for (lpn=(struct LibPath *)gv->rpaths.first; lpn->n.next!=NULL;
       lpn=(struct LibPath *)lpn->n.next) {
    elf32_dynamicentry(gv,DT_RPATH,elf32_adddynstr(lpn->path),NULL);
  }

  /* generate .hash section */
  elf32_makehash(gv);

  /* allocate and populate .dynstr section */
  if (dynstr = find_sect_name(gv->dynobj,dynstr_name)) {
    dynstr->size = elf32dstrlist.nextindex;
    dynstr->data = alloc(dynstr->size);
    elf32_putstrtab(dynstr->data,&elf32dstrlist);
  }
  else
    ierror("%s %s missing",fn,dynstr_name);

  /* allocate .dynsym section - populate it later, when addresses are fixed */
  if (dynsym = find_sect_name(gv->dynobj,dynsym_name)) {
    dynsym->size = elf32dsymlist.nextindex * sizeof(struct Elf32_Sym);
    dynsym->data = alloc(dynsym->size);
  }
  else
    ierror("%s %s missing",fn,dynsym_name);

  /* finish .dynamic section */
  elf32_dynamicentry(gv,DT_HASH,0,find_sect_name(gv->dynobj,hash_name));
  elf32_dynamicentry(gv,DT_STRTAB,0,dynstr);
  elf32_dynamicentry(gv,DT_SYMTAB,0,dynsym);
  elf32_dynamicentry(gv,DT_STRSZ,dynstr->size,NULL);
  elf32_dynamicentry(gv,DT_SYMENT,sizeof(struct Elf32_Sym),NULL);
  elf32_dynamicentry(gv,DT_DEBUG,0,NULL); /* needed? */
  /* do we have a .plt or .got section (target dependant) */
  if (pltgot = find_sect_name(gv->dynobj,pltgot_name)) {
    elf32_dynamicentry(gv,DT_PLTGOT,0,pltgot);    
  }
  /* do we have .plt relocations? */
  if (pltrelocs) {
    elf32_dynamicentry(gv,DT_PLTRELSZ,pltrelocs->size,NULL);
    elf32_dynamicentry(gv,DT_PLTREL,
                       gv->reloctab_format==RTAB_ADDEND?DT_RELA:DT_REL,
                       NULL);
    elf32_dynamicentry(gv,DT_JMPREL,0,pltrelocs);
  }
  /* do we have any other dynamic relocations? */
  if (dynrelocs) {
    if (gv->reloctab_format == RTAB_ADDEND) {
      elf32_dynamicentry(gv,DT_RELA,0,dynrelocs);
      elf32_dynamicentry(gv,DT_RELASZ,dynrelocs->size,NULL);
      elf32_dynamicentry(gv,DT_RELAENT,sizeof(struct Elf32_Rela),NULL);
    }
    else {
      elf32_dynamicentry(gv,DT_REL,0,dynrelocs);
      elf32_dynamicentry(gv,DT_RELSZ,dynrelocs->size,NULL);
      elf32_dynamicentry(gv,DT_RELENT,sizeof(struct Elf32_Rel),NULL);
    }
  }
  /* end tag */
  elf32_dynamicentry(gv,DT_NULL,0,NULL);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, 0x10(%rsp)
movq %rdi, %r14
cmpq $0x0, 0x1e0(%rdi)
jne 0x163bb
leaq 0xd17c(%rip), %rdi      # 0x23529
leaq 0xd24f(%rip), %rsi      # 0x23603
xorl %eax, %eax
callq 0x52b0
movq 0xe0(%r14), %rsi
testq %rsi, %rsi
je 0x163eb
cmpl $0x0, 0x58(%r14)
je 0x163eb
leaq 0x193db(%rip), %rdi     # 0x2f7b0
callq 0x167f2
movq %r14, %rdi
movl $0xe, %esi
movl %eax, %edx
xorl %ecx, %ecx
callq 0x1629f
movq 0xf0(%r14), %rbx
cmpq $0x0, (%rbx)
je 0x16425
leaq 0x193b1(%rip), %r15     # 0x2f7b0
movq 0x10(%rbx), %rsi
movq %r15, %rdi
callq 0x167f2
movq %r14, %rdi
movl $0xf, %esi
movl %eax, %edx
xorl %ecx, %ecx
callq 0x1629f
movq (%rbx), %rbx
cmpq $0x0, (%rbx)
jne 0x163ff
movb 0x193e5(%rip), %al      # 0x2f810
movl 0x19346(%rip), %r13d    # 0x2f778
movl $0x1, %edx
leaq 0xcfd2(%rip), %rcx      # 0x23410
movl $0x1, %esi
movq %rsi, %r15
movq (%rcx,%rdx,8), %rsi
cmpq %r13, %rsi
ja 0x1645c
leaq 0x1(%rdx), %rdi
cmpq $0x10, %rdx
movq %rdi, %rdx
jne 0x16443
xorl %ebp, %ebp
cmpb $0x1, %al
sete %bl
movq %r14, 0x8(%rsp)
movq 0x1e0(%r14), %rdi
leaq 0xcf61(%rip), %rsi      # 0x233d7
callq 0xbdc5
testq %rax, %rax
je 0x1651c
movq %rax, %r14
movb %bl, %bpl
leaq (%r15,%r13), %rdi
addq $0x2, %rdi
shlq $0x2, %rdi
movq %rdi, 0x48(%rax)
callq 0x6686
movq %rax, %r12
movq %rax, 0x40(%r14)
movl %ebp, %edi
movq %rax, %rsi
movl %r15d, %edx
callq 0x69a0
leaq 0x4(%r12), %rsi
movl %ebp, %edi
movl %r13d, %edx
callq 0x69a0
movq 0x19287(%rip), %r14     # 0x2f750
cmpq $0x0, (%r14)
je 0x16531
leaq 0x2(%r15), %rax
leaq (%r12,%rax,4), %rbx
addq $0x8, %r12
movq 0x18(%r14), %rdi
callq 0x6d94
xorl %edx, %edx
divq %r15
leaq (%r12,%rdx,4), %r13
movl %ebp, %edi
movq %r13, %rsi
callq 0x696f
testl %eax, %eax
je 0x16503
movl %eax, %eax
leaq (%rbx,%rax,4), %r13
jmp 0x164ed
movl 0x30(%r14), %edx
movl %ebp, %edi
movq %r13, %rsi
callq 0x69a0
movq (%r14), %r14
cmpq $0x0, (%r14)
jne 0x164db
jmp 0x16531
leaq 0xd43a(%rip), %rdi      # 0x2395d
leaq 0xcead(%rip), %rsi      # 0x233d7
xorl %eax, %eax
callq 0x52b0
movq 0x8(%rsp), %rbx
movq 0x1e0(%rbx), %rdi
leaq 0xcea1(%rip), %rsi      # 0x233e5
callq 0xbdc5
movq %rax, %r15
testq %rax, %rax
je 0x165aa
movl 0x19281(%rip), %edi     # 0x2f7d8
leaq 0x19252(%rip), %r14     # 0x2f7b0
movq %rdi, 0x48(%r15)
callq 0x6638
movq %rax, %r12
movq %rax, 0x40(%r15)
movq %r14, %rdi
movq 0x8(%rsp), %rbx
callq 0x673f
testq %rax, %rax
je 0x165c6
leaq 0x19229(%rip), %r13     # 0x2f7b0
movq 0x18(%rax), %rax
movb (%rax), %cl
incq %rax
movb %cl, (%r12)
incq %r12
testb %cl, %cl
jne 0x1658b
movq %r13, %rdi
callq 0x673f
testq %rax, %rax
jne 0x16587
jmp 0x165c6
leaq 0xd064(%rip), %rdi      # 0x23615
leaq 0xd04b(%rip), %rsi      # 0x23603
leaq 0xce26(%rip), %rdx      # 0x233e5
xorl %eax, %eax
callq 0x52b0
movq 0x1e0(%rbx), %rdi
leaq 0xce09(%rip), %rsi      # 0x233dd
callq 0xbdc5
movq %rax, %r12
testq %rax, %rax
je 0x165fc
movl 0x19191(%rip), %edi     # 0x2f778
shlq $0x4, %rdi
movq %rdi, 0x48(%r12)
callq 0x6638
movq %rax, 0x40(%r12)
jmp 0x16618
leaq 0xd012(%rip), %rdi      # 0x23615
leaq 0xcff9(%rip), %rsi      # 0x23603
leaq 0xcdcc(%rip), %rdx      # 0x233dd
xorl %eax, %eax
callq 0x52b0
movq 0x1e0(%rbx), %rdi
leaq 0xcdb1(%rip), %rsi      # 0x233d7
callq 0xbdc5
movq %rbx, %rdi
movl $0x4, %esi
xorl %edx, %edx
movq %rax, %rcx
callq 0x1629f
movq %rbx, %rdi
movl $0x5, %esi
xorl %edx, %edx
movq %r15, %rcx
callq 0x1629f
movq %rbx, %rdi
movl $0x6, %esi
xorl %edx, %edx
movq %r12, %rcx
callq 0x1629f
movl 0x48(%r15), %edx
movq %rbx, %rdi
movl $0xa, %esi
xorl %ecx, %ecx
callq 0x1629f
movq %rbx, %rdi
movl $0xb, %esi
movl $0x10, %edx
xorl %ecx, %ecx
callq 0x1629f
movq %rbx, %rdi
movl $0x15, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1629f
movq 0x1e0(%rbx), %rdi
movq 0x10(%rsp), %rsi
callq 0xbdc5
testq %rax, %rax
je 0x166c1
movq %rbx, %rdi
movl $0x3, %esi
xorl %edx, %edx
movq %rax, %rcx
callq 0x1629f
movq 0x1d228(%rip), %rax     # 0x338f0
testq %rax, %rax
je 0x16715
movl 0x48(%rax), %edx
movq %rbx, %rdi
movl $0x2, %esi
xorl %ecx, %ecx
callq 0x1629f
cmpb $0x2, 0x6e(%rbx)
movl $0x7, %eax
movl $0x11, %edx
cmovel %eax, %edx
movq %rbx, %rdi
movl $0x14, %esi
xorl %ecx, %ecx
callq 0x1629f
movq 0x1d1ea(%rip), %rcx     # 0x338f0
movq %rbx, %rdi
movl $0x17, %esi
xorl %edx, %edx
callq 0x1629f
movq 0x1d1dc(%rip), %rcx     # 0x338f8
testq %rcx, %rcx
je 0x1679a
cmpb $0x2, 0x6e(%rbx)
jne 0x1675e
movq %rbx, %rdi
movl $0x7, %esi
xorl %edx, %edx
callq 0x1629f
movq 0x1d1bb(%rip), %rax     # 0x338f8
movl 0x48(%rax), %edx
movq %rbx, %rdi
movl $0x8, %esi
xorl %ecx, %ecx
callq 0x1629f
movq %rbx, %rdi
movl $0x9, %esi
movl $0xc, %edx
jmp 0x16793
movq %rbx, %rdi
movl $0x11, %esi
xorl %edx, %edx
callq 0x1629f
movq 0x1d184(%rip), %rax     # 0x338f8
movl 0x48(%rax), %edx
movq %rbx, %rdi
movl $0x12, %esi
xorl %ecx, %ecx
callq 0x1629f
movq %rbx, %rdi
movl $0x13, %esi
movl $0x8, %edx
xorl %ecx, %ecx
callq 0x1629f
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1629f