// File: /workspace/github_c_makefile_star2_O1/deplinenoise[P]vlink/t_elf32.c
// Function: elf32_addrelocs
void elf32_addrelocs(struct GlobalVars *gv,
                     uint8_t (*reloc_vlink2elf)(struct Reloc *))
/* creates relocations for all sections */
{
  bool be = elf32_endianess == _BIG_ENDIAN_;
  struct LinkedSection *ls;
  struct Reloc *rel;
  uint32_t sroffs=0,roffs=0;

  for (ls=(struct LinkedSection *)gv->lnksec.first;
       ls->n.next!=NULL; ls=(struct LinkedSection *)ls->n.next) {
    sroffs = roffs;

    /* relocations */
    for (rel=(struct Reloc *)ls->relocs.first;
         rel->n.next!=NULL; rel=(struct Reloc *)rel->n.next) {
      roffs += elf32_addrela(gv,ls,rel,be,reloc_vlink2elf);
    }

    /* external references */
    for (rel=(struct Reloc *)ls->xrefs.first;
         rel->n.next!=NULL; rel=(struct Reloc *)rel->n.next) {
      roffs += elf32_addrela(gv,ls,rel,be,reloc_vlink2elf);
    }

    if (roffs != sroffs) {
      /* create ".rel(a).name" header */
      char *relname = (char *)alloc(strlen(ls->name)+6);

      sprintf(relname,".%s%s",
              gv->reloctab_format==RTAB_ADDEND ? "rela" : "rel",
              ls->name);
      elf32_addshdr(elf32_addshdrstr(relname),
                    gv->reloctab_format==RTAB_ADDEND ? SHT_RELA : SHT_REL,
                    0,0,sroffs,roffs-sroffs,0,(uint32_t)ls->index,4,
                    gv->reloctab_format==RTAB_ADDEND ?
                      sizeof(struct Elf32_Rela) : sizeof(struct Elf32_Rel),
                    be);
      /* sroffs is relative and will be corrected later */
      /* sh_link will be initialized, when .symtab exists */
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
xorl %r15d, %r15d
cmpb $0x1, 0x17d3a(%rip)     # 0x2f810
sete %al
movq 0x1c0(%rdi), %r12
cmpq $0x0, (%r12)
je 0x17c1d
movq %rsi, %rbx
movq %rdi, %r14
movb %al, %r15b
xorl %eax, %eax
movl %eax, %r13d
movl %eax, 0xc(%rsp)
movq 0x80(%r12), %rbp
cmpq $0x0, (%rbp)
je 0x17b33
movl 0xc(%rsp), %r13d
movq %r14, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movl %r15d, %ecx
movq %rbx, %r8
callq 0x17c2c
addl %eax, %r13d
movq (%rbp), %rbp
cmpq $0x0, (%rbp)
jne 0x17b11
movq 0x98(%r12), %rbp
cmpq $0x0, (%rbp)
je 0x17b5f
movq %r14, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movl %r15d, %ecx
movq %rbx, %r8
callq 0x17c2c
addl %eax, %r13d
movq (%rbp), %rbp
jmp 0x17b3b
movl %r13d, %ebp
movl 0xc(%rsp), %eax
subl %eax, %ebp
je 0x17c0b
movq 0x18(%r12), %rdi
callq 0x50e0
leaq 0x6(%rax), %rdi
callq 0x6668
movq %rax, %rdi
movq %rax, 0x10(%rsp)
cmpb $0x2, 0x6e(%r14)
leaq 0xbe07(%rip), %rdx      # 0x2399c
leaq 0xbdfa(%rip), %rax      # 0x23996
cmoveq %rax, %rdx
movq 0x18(%r12), %rcx
leaq 0xbc22(%rip), %rsi      # 0x237ce
xorl %eax, %eax
callq 0x5250
leaq 0x17c26(%rip), %rdi     # 0x2f7e0
movq 0x10(%rsp), %rsi
callq 0x169a2
xorl %ecx, %ecx
xorl %edx, %edx
cmpb $0x2, 0x6e(%r14)
sete %cl
setne %dl
leal (%rdx,%rdx,4), %esi
addl $0x4, %esi
movl 0x10(%r12), %r10d
leal 0x8(,%rcx,4), %r11d
subq $0x8, %rsp
movl %eax, %edi
xorl %edx, %edx
xorl %ecx, %ecx
movl 0x14(%rsp), %r8d
movl %ebp, %r9d
pushq %r15
pushq %r11
pushq $0x4
pushq %r10
pushq $0x0
callq 0x17e2a
addq $0x30, %rsp
movq (%r12), %r12
cmpq $0x0, (%r12)
movl %r13d, %eax
jne 0x17af9
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq