Forums before death by AOL, social media and spammers... "We can't have nice things"
|    alt.os.development    |    Operating system development chatter    |    4,255 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 3,612 of 4,255    |
|    mutazilah@gmail.com to All    |
|    clang bug    |
|    01 Mar 23 08:06:26    |
   
   From: muta...@gmail.com   
      
   Hello.   
      
    #Shouldn't @there be two mov `instructions` for 2 parameters?   
      
   I only see the second.   
      
   .ident "Android (7714059, based on r416183c1) clang version 12.0.8   
   (https://android.googlesource.com/toolchain/llvm-project c935d99   
   7cf2016289302412d708641d52d2f7ee)"   
      
   mystart takes 2 parameters. I can see the second parameter:   
      
    movl %eax, 4(%esp)   
      
   but I don't see the first parameter, which I expect to be inserted   
   at 0(%esp)   
      
   /* written by Paul Edwards */   
   /* released to the public domain */   
      
   #include "errno.h"   
   #include "stddef.h"   
      
   /* malloc calls get this */   
   static char membuf[31000000];   
   static char *newmembuf = membuf;   
      
   extern int __mystart(int argc, char   
   **argv);   
   extern int __exita(int rc);   
      
   int *paul;   
      
   #ifdef NEED_MPROTECT   
   extern int __mprotect(void *buf,   
   size_t len, int prot);   
      
      
      
    .text   
    .p2align 4   
    .globl _start   
    .type _start, @function   
   _start:   
   .LFB0:   
    .cfi_startproc   
    endbr32   
    pushl %ebx   
    .cfi_def_cfa_offset 8   
    .cfi_offset 3, -8   
    subl $8, %esp   
    .cfi_def_cfa_offset 16   
    leal 12(%esp), %eax   
    subl $8, %esp   
    .cfi_def_cfa_offset 24   
    movl %eax, paul   
    leal 24(%esp), %eax   
    pushl %eax   
      
      
      
   /* written by Paul Edwards */   
   /* released to the public domain */   
      
   #include "errno.h"   
   #include "stddef.h"   
      
   /* malloc calls get this */   
   static char membuf[31000000];   
   static char *newmembuf = membuf;   
      
   extern int __mystart(int argc, char   
   **argv);   
   extern int __exita(int rc);   
      
   int *paul;   
      
   #ifdef NEED_MPROTECT   
   extern int __mprotect(void *buf,   
   size_t len, int prot);   
      
      
      
    .text   
    .file "linstart.c"   
    .globl _start # -- Begin function _start   
    .p2align 4, 0x90   
    .type _start,@function   
   _start: # @_start   
   # %bb.0:   
    pushl %esi   
    subl $8, %esp   
    leal 12(%esp), %eax   
    movl %eax, paul   
    leal 16(%esp), %eax   
    movl %eax, 4(%esp)   
    calll __mystart   
    movl %eax, %esi   
    movl %eax, (%esp)   
    calll __exita   
    movl %esi, %eax   
    addl $8, %esp   
    popl %esi   
    retl   
   .Lfunc_end0:   
      
      
      
   /* Startup code for Linux */   
   /* written by Paul Edwards */   
   /* released to the public domain */   
      
   #include "errno.h"   
   #include "stddef.h"   
      
   /* malloc calls get this */   
   static char membuf[31000000];   
   static char *newmembuf = membuf;   
      
   extern int __mystart(int argc, char **argv);   
   extern int __exita(int rc);   
      
   int *paul;   
      
   #ifdef NEED_MPROTECT   
   extern int __mprotect(void *buf, size_t len, int prot);   
      
   #define PROT_READ 1   
   #define PROT_WRITE 2   
   #define PROT_EXEC 4   
   #endif   
      
   /* We can get away with a minimal startup code, plus make it   
    a C program. There is no return address. Instead, on the   
    stack is a count, followed by all the parameters as pointers */   
      
   int _start(char *p)   
   {   
    int rc;   
    char *argv[2] = { "prog", NULL };   
      
   #ifdef NEED_MPROTECT   
    /* make malloced memory executable */   
    /* most environments already make the memory executable */   
    /* but some certainly don't */   
    /* there doesn't appear to be a syscall to get the page size to   
    ensure page alignment (as required), and I read that some   
    environments have 4k page sizes but mprotect requires 16k   
    alignment. So for now we'll just go with 16k */   
    size_t blksize = 16 * 1024;   
    size_t numblks;   
      
    newmembuf = membuf + blksize; /* could waste memory here */   
    newmembuf = newmembuf - (unsigned int)newmembuf % blksize;   
    numblks = sizeof membuf / blksize;   
    numblks -= 2; /* if already aligned, we wasted an extra block */   
    rc = __mprotect(newmembuf,   
    numblks * blksize,   
    PROT_READ | PROT_WRITE | PROT_EXEC);   
    if (rc != 0) return (rc);   
   #endif   
      
    /* I don't know what the official rules for ARM are, but   
    looking at the stack on entry showed that this code   
    would work */   
   #ifdef __ARM__   
      
   #if defined(__UNOPT__)   
    rc = __mystart(*(int *)(&p + 5), &p + 6);   
   #else   
    rc = __start(*(int *)(&p + 6), &p + 7);   
   #endif   
      
   #else   
    paul = (int *)(&p - 1);   
    rc = __mystart(*(int *)(&p - 1), &p);   
    /* rc = __start(1, argv); */   
   #endif   
    __exita(rc);   
    return (rc);   
   }   
      
      
   void *__allocmem(size_t size)   
   {   
    return (newmembuf);   
   }   
      
      
   #if defined(__WATCOMC__)   
      
   #define CTYP __cdecl   
      
   /* this is invoked by long double manipulations   
    in stdio.c and needs to be done properly */   
      
   int CTYP _CHP(void)   
   {   
    return (0);   
   }   
      
   /* don't know what these are */   
      
   void CTYP cstart_(void) { return; }   
   void CTYP _argc(void) { return; }   
   void CTYP argc(void) { return; }   
   void CTYP _8087(void) { return; }   
      
   #endif   
      
      
      
   Holy cow I need a real computer   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca