// File: /workspace/github_c_makefile_star2_O2/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, 0x8(%rsp)
movq %rdi, %r14
cmpq $0x0, 0x1e0(%rdi)
jne 0x151fe
leaq 0xc359(%rip), %rdi      # 0x21549
leaq 0xc42c(%rip), %rsi      # 0x21623
xorl %eax, %eax
callq 0x6b2c
movq 0xe0(%r14), %rdi
testq %rdi, %rdi
je 0x15225
cmpl $0x0, 0x58(%r14)
je 0x15225
callq 0x15590
pushq $0xe
popq %rsi
movq %r14, %rdi
movl %eax, %edx
xorl %ecx, %ecx
callq 0x150e7
leaq 0xf0(%r14), %rbx
pushq $0xf
popq %rbp
movq (%rbx), %rbx
cmpq $0x0, (%rbx)
je 0x15251
movq 0x10(%rbx), %rdi
callq 0x15590
movq %r14, %rdi
movl %ebp, %esi
movl %eax, %edx
xorl %ecx, %ecx
callq 0x150e7
jmp 0x1522f
xorl %ebp, %ebp
cmpb $0x1, 0x1a5c6(%rip)     # 0x2f820
sete %bpl
movl 0x1a523(%rip), %r13d    # 0x2f788
xorl %eax, %eax
leaq 0xc1c2(%rip), %rcx      # 0x21430
cmpq $0x10, %rax
je 0x15286
movq (%rcx,%rax,8), %r15
leaq 0x1(%rax), %rdx
cmpq %r13, 0x8(%rcx,%rax,8)
movq %rdx, %rax
jbe 0x1526e
movq %r14, 0x10(%rsp)
movq 0x1e0(%r14), %rdi
leaq 0xc15e(%rip), %rsi      # 0x213f7
callq 0xb79b
testq %rax, %rax
je 0x15335
movq %rax, %r14
leaq (%r15,%r13), %rdi
addq $0x2, %rdi
shlq $0x2, %rdi
movq %rdi, 0x48(%rax)
callq 0x638a
movq %rax, %r12
movq %rax, 0x40(%r14)
movl %ebp, %edi
movq %rax, %rsi
movl %r15d, %edx
callq 0x6681
leaq 0x4(%r12), %rsi
movl %ebp, %edi
movl %r13d, %edx
callq 0x6681
leaq (%r12,%r15,4), %r14
addq $0x8, %r14
addq $0x8, %r12
leaq 0x1a46b(%rip), %rbx     # 0x2f760
movq (%rbx), %rbx
cmpq $0x0, (%rbx)
je 0x1534a
movq 0x18(%rbx), %rdi
callq 0x69ee
xorl %edx, %edx
divq %r15
leaq (%r12,%rdx,4), %r13
movl %ebp, %edi
movq %r13, %rsi
callq 0x664d
testl %eax, %eax
je 0x15326
movl %eax, %eax
leaq (%r14,%rax,4), %r13
jmp 0x15310
movl 0x30(%rbx), %edx
movl %ebp, %edi
movq %r13, %rsi
callq 0x6681
jmp 0x152f5
leaq 0xc641(%rip), %rdi      # 0x2197d
leaq 0xc0b4(%rip), %rsi      # 0x213f7
xorl %eax, %eax
callq 0x6b2c
movq 0x10(%rsp), %rbx
movq 0x1e0(%rbx), %rdi
leaq 0xc0a8(%rip), %rsi      # 0x21405
callq 0xb79b
movq %rax, %r15
testq %rax, %rax
je 0x153af
movl 0x1a478(%rip), %edi     # 0x2f7e8
movq %rdi, 0x48(%r15)
callq 0x6340
movq %rax, %r12
movq %rax, 0x40(%r15)
leaq 0x1a439(%rip), %r13     # 0x2f7c0
movq 0x8(%rsp), %r14
movq %r13, %rdi
callq 0x642a
testq %rax, %rax
je 0x153d0
movq 0x18(%rax), %rax
movb (%rax), %cl
incq %rax
movb %cl, (%r12)
incq %r12
testb %cl, %cl
jne 0x1539d
jmp 0x1538c
leaq 0xc27f(%rip), %rdi      # 0x21635
leaq 0xc266(%rip), %rsi      # 0x21623
leaq 0xc041(%rip), %rdx      # 0x21405
xorl %eax, %eax
callq 0x6b2c
movq 0x8(%rsp), %r14
movq 0x1e0(%rbx), %rdi
leaq 0xc01f(%rip), %rsi      # 0x213fd
callq 0xb79b
movq %rax, %r12
testq %rax, %rax
je 0x15406
movl 0x1a397(%rip), %edi     # 0x2f788
shlq $0x4, %rdi
movq %rdi, 0x48(%r12)
callq 0x6340
movq %rax, 0x40(%r12)
jmp 0x15422
leaq 0xc228(%rip), %rdi      # 0x21635
leaq 0xc20f(%rip), %rsi      # 0x21623
leaq 0xbfe2(%rip), %rdx      # 0x213fd
xorl %eax, %eax
callq 0x6b2c
movq 0x1e0(%rbx), %rdi
leaq 0xbfc7(%rip), %rsi      # 0x213f7
callq 0xb79b
pushq $0x4
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
movq %rax, %rcx
callq 0x150e7
pushq $0x5
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
movq %r15, %rcx
callq 0x150e7
pushq $0x6
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
movq %r12, %rcx
callq 0x150e7
movl 0x48(%r15), %edx
pushq $0xa
popq %rsi
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x150e7
pushq $0xb
popq %rsi
pushq $0x10
popq %rdx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x150e7
pushq $0x15
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x150e7
movq 0x1e0(%rbx), %rdi
movq %r14, %rsi
callq 0xb79b
testq %rax, %rax
je 0x154b9
pushq $0x3
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
movq %rax, %rcx
callq 0x150e7
movq 0x1e820(%rip), %rax     # 0x33ce0
testq %rax, %rax
je 0x15503
movl 0x48(%rax), %edx
pushq $0x2
popq %rsi
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x150e7
cmpb $0x2, 0x6e(%rbx)
pushq $0x7
popq %rax
pushq $0x11
popq %rdx
cmovel %eax, %edx
pushq $0x14
popq %rsi
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x150e7
movq 0x1e7ea(%rip), %rcx     # 0x33ce0
pushq $0x17
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x150e7
movq 0x1e7de(%rip), %rcx     # 0x33ce8
testq %rcx, %rcx
je 0x15574
cmpb $0x2, 0x6e(%rbx)
jne 0x15540
pushq $0x7
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x150e7
movq 0x1e7bf(%rip), %rax     # 0x33ce8
movl 0x48(%rax), %edx
pushq $0x8
popq %rsi
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x150e7
pushq $0x9
popq %rsi
pushq $0xc
jmp 0x15569
pushq $0x11
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x150e7
movq 0x1e794(%rip), %rax     # 0x33ce8
movl 0x48(%rax), %edx
pushq $0x12
popq %rsi
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x150e7
pushq $0x13
popq %rsi
pushq $0x8
popq %rdx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x150e7
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 0x150e7