// File: /workspace/github_c_makefile_star2_O3/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 $0x138, %rsp            # imm = 0x138
movq %r9, 0x20(%rsp)
movq %r8, %r14
movq %rcx, 0x8(%rsp)
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r13
xorl %eax, %eax
cmpl $0x4, 0x170(%rsp)
setne %al
movl %eax, %ecx
shll $0x5, %ecx
shll $0x4, %eax
movq 0x20(%rdx,%rax), %r9
movq 0x18(%rdx,%rcx), %rbp
movq 0x20(%rsi), %rcx
leaq 0xd622(%rip), %rdx      # 0x2357e
leaq 0x30(%rsp), %r12
movl $0x100, %esi            # imm = 0x100
movq %r12, %rdi
movq %rbp, %r8
movq %r9, 0x18(%rsp)
xorl %eax, %eax
callq 0x5100
movq %r12, %rdi
callq 0x669d
movq 0x38(%r15), %r8
subq $0x8, %rsp
movq %r13, 0x30(%rsp)
movq %r13, %rdi
movq %r15, %rsi
movq %rax, %rdx
xorl %ecx, %ecx
movl $0x2, %r9d
xorl %eax, %eax
pushq %rax
pushq %r14
pushq $0x1
pushq 0x28(%rsp)
pushq %rax
callq 0xaad4
addq $0x30, %rsp
movq %rax, %r12
testq %rax, %rax
jne 0x160d0
movq 0x18(%rsp), %r13
movq %rbx, 0x10(%rsp)
movq %r14, 0x8(%rsp)
movq 0x20(%rsp), %rbx
movq 0x10(%r15), %rsi
leaq 0x30(%rsp), %rdx
movq 0x28(%rsp), %r14
movq %r14, %rdi
callq 0xac96
movq %rax, %r12
testq %rax, %rax
movq %r14, %rsi
jne 0x1601a
movq 0x20(%r15), %rdx
movq 0x20(%rbp), %rcx
movq %rsi, %r14
leaq 0xd584(%rip), %rdi      # 0x2358a
leaq 0xd55c(%rip), %rsi      # 0x23569
movq %r13, %r8
xorl %eax, %eax
callq 0x52b0
movq %r14, %rsi
movl 0x170(%rsp), %eax
cmpl $0x4, %eax
movq %rbx, %r14
movq 0x10(%rsp), %rbx
jne 0x16058
movq 0x38(%r15), %r9
movq %rsi, %rbx
movq %rsi, %rdi
movq %r15, %rsi
xorl %edx, %edx
movq %rbp, %rcx
xorl %r8d, %r8d
pushq %r13
pushq $0x1
callq 0xb13c
addq $0x10, %rsp
movq %rbx, %r13
movq %rax, %rbx
jmp 0x16091
movq 0x20(%rbx), %rdx
movq 0x38(%r15), %r9
cltq
leaq 0xda1f(%rip), %rcx      # 0x23a88
movzbl (%rax,%rcx), %eax
movq %rsi, %r13
movq %rsi, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
xorl %r8d, %r8d
pushq $0x0
pushq %rax
callq 0xb13c
addq $0x10, %rsp
movq %rbx, %rcx
movq %rax, %rbx
movq %rcx, 0x18(%rax)
movq %r15, %rdi
movq %rbx, %rsi
xorl %edx, %edx
movl $0x20, %ecx
movq $-0x1, %r8
callq 0xb1f1
movq 0x1e0(%r13), %rdi
xorl %edx, %edx
cmpb $0x2, 0x6e(%r13)
sete %dl
movq %rbx, %rsi
callq 0x160e5
movq 0x8(%rsp), %rax
addq %rax, 0x38(%r15)
addq %r14, 0x48(%r15)
movq %r12, %rax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq