// File: /workspace/github_c_makefile_star2_O2/deplinenoise[P]vlink/t_elf32.c
// Function: elf32_pltgotentry
struct Symbol *elf32_pltgotentry(struct GlobalVars *gv,struct Section *sec,
                                 DynArg a,uint8_t entrysymtype,
                                 unsigned long offsadd,unsigned long sizeadd,
                                 int etype)
/* Make a table entry for indirectly accessing a location from an external
   symbol defintion (GOT_ENTRY/PLT_ENTRY) or a local relocation (GOT_LOCAL).
   The entry has a size of offsadd bytes, while the table section sec will
   become sizeadd bytes larger per entry. */
{
  const char *fn = "elf32_pltgotentry():";
  char entryname[MAXLEN];
  struct Symbol *tabsym;
  struct Section *refsec;
  unsigned long refoffs;

  /* determine reference section and offset of ext. symbol or local reloc */
  if (etype == GOT_LOCAL) {
    refsec = a.rel->relocsect.ptr;
    refoffs = a.rel->offset;
  }
  else {
    refsec = a.sym->relsect;
    refoffs = (unsigned long)a.sym->value;
  }

  /* generate internal symbol name for this reference */
  snprintf(entryname,MAXLEN," %s@%lx@%lx",
           sec->name,(unsigned long)refsec,refoffs);

  /* create internal symbol, or return old one, when already present */
  tabsym = addsymbol(gv,sec,allocstring(entryname),NULL,(lword)sec->offset,
                     SYM_RELOC,0,entrysymtype,SYMB_LOCAL,offsadd,FALSE);

  /* tabsym is NULL when it was just created, otherwise we already got it */
  if (tabsym == NULL) {
    static uint8_t dyn_reloc_types[] = { R_NONE,R_GLOBDAT,R_JMPSLOT,R_COPY };
    struct Reloc *r;
    uint8_t rtype;

    tabsym = findlocsymbol(gv,sec->obj,entryname);
    if (tabsym == NULL) {
      ierror("%s %s-symbol refering to %s+%lx disappeared",
             fn,sec->name,refsec->name,refoffs);
    }

    /* create a relocation for the new entry */
    if (etype == GOT_LOCAL) {
      /* local symbol: GOT relocation can be resolved now */
      r = newreloc(gv,sec,NULL,refsec,0,sec->offset,R_ABS,(lword)refoffs);
    }
    else {
      /* we need a dynamic linker relocation at the entry's offset */
      r = newreloc(gv,sec,a.sym->name,NULL,0,sec->offset,
                   dyn_reloc_types[etype],0);
      r->relocsect.symbol = a.sym;  /* resolve with external symbol */
      /* Possible enhancement: Find out whether referenced symbol resides
         in an uninitialized section, without a relocation, then we don't
         need an R_COPY relocation either! */
    }
    addreloc(sec,r,0,32,-1);  /* size,mask only important for R_ABS */
    elf32_dynreloc(gv->dynobj,r,gv->reloctab_format==RTAB_ADDEND);

    /* increase offset and size counters of table-section */
    sec->offset += offsadd;
    sec->size += sizeadd;
  }

  return tabsym;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %r9, 0x18(%rsp)
movq %r8, %rbx
movq %rcx, (%rsp)
movq %rdx, %r13
movq %rsi, %r15
movq %rdi, %rbp
xorl %eax, %eax
cmpl $0x4, 0x160(%rsp)
setne %al
movl %eax, %ecx
shll $0x5, %ecx
shll $0x4, %eax
movq 0x20(%rdx,%rax), %r9
movq 0x18(%rdx,%rcx), %r14
movq 0x20(%rsi), %rcx
leaq 0xc7ea(%rip), %rdx      # 0x2159e
leaq 0x20(%rsp), %r12
movl $0x100, %esi            # imm = 0x100
movq %r12, %rdi
movq %r14, %r8
movq %r9, 0x10(%rsp)
xorl %eax, %eax
callq 0x5100
movq %r12, %rdi
callq 0x63a1
movq 0x38(%r15), %r8
subq $0x8, %rsp
pushq $0x2
popq %r9
movq %rbp, %r12
movq %rbp, %rdi
movq %r15, %rsi
movq %rax, %rdx
xorl %ecx, %ecx
pushq $0x0
pushq %rbx
pushq $0x1
pushq 0x20(%rsp)
pushq $0x0
callq 0xa5d5
addq $0x30, %rsp
movq %rax, %rbp
testq %rax, %rax
jne 0x14f17
movq %r13, 0x8(%rsp)
movq %rbx, (%rsp)
movq 0x18(%rsp), %r13
movq 0x10(%r15), %rsi
leaq 0x20(%rsp), %rdx
movq %r12, %rdi
callq 0xa780
movq %rax, %rbp
testq %rax, %rax
movq %r12, %rbx
movq 0x10(%rsp), %r10
jne 0x14e67
movq 0x20(%r15), %rdx
movq 0x20(%r14), %rcx
leaq 0xc75a(%rip), %rdi      # 0x215aa
leaq 0xc732(%rip), %rsi      # 0x21589
movq %r10, %r8
xorl %eax, %eax
movq %r10, %r12
callq 0x6b2c
movq %r12, %r10
movl 0x160(%rsp), %eax
cmpl $0x4, %eax
movq %r13, %r12
movq 0x8(%rsp), %r13
jne 0x14ea0
movq 0x38(%r15), %r9
movq %rbx, %rdi
movq %r15, %rsi
xorl %edx, %edx
movq %r14, %rcx
xorl %r8d, %r8d
pushq %r10
pushq $0x1
callq 0xabec
popq %rcx
popq %rdx
movq %rbx, %r14
movq %rax, %rbx
jmp 0x14ede
movq 0x20(%r13), %rdx
movq 0x38(%r15), %r9
cltq
leaq 0xcbf7(%rip), %rcx      # 0x21aa8
movzbl (%rax,%rcx), %eax
subq $0x10, %rsp
andq $0x0, 0x8(%rsp)
movl %eax, (%rsp)
movq %rbx, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0xabec
popq %rcx
popq %rdx
movq %rbx, %r14
movq %rax, %rbx
movq %r13, 0x18(%rax)
pushq $0x20
popq %rcx
pushq $-0x1
popq %r8
movq %r15, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0xac9f
movq 0x1e0(%r14), %rdi
xorl %edx, %edx
cmpb $0x2, 0x6e(%r14)
sete %dl
movq %rbx, %rsi
callq 0x14f2c
movq (%rsp), %rax
addq %rax, 0x38(%r15)
addq %r12, 0x48(%r15)
movq %rbp, %rax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq