Changeset a15586 in git


Ignore:
Timestamp:
Nov 9, 2011, 3:18:30 PM (13 years ago)
Author:
Burcin Erocal <burcin@…>
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', 'b52fc4b2495505785981d640dcf7eb3e456778ef')
Children:
61b2e164cc25fb30ef24c1f947cb188d72824bb7
Parents:
2cba98d996d3093dcc04573bc6024bb750518d4f
git-author:
Burcin Erocal <burcin@erocal.org>2011-11-09 15:18:30+01:00
git-committer:
Oleksandr Motsak <motsak@mathematik.uni-kl.de>2011-11-09 20:32:41+01:00
Message:
Remove inline assembly hacks used to get the function return address in omalloc.

omalloc included inline assembly code from the dmalloc library to figure
out the return address of a function in debug mode. These hacks made
assumptions about the registers which break with recent GCC versions. We
remove the hacks and rely on the __builtin_return_address() function
provided by GCC.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • omalloc/omReturn.h

    r2cba98d ra15586  
    2424
    2525/*
    26  * This file contains the definition of the SET_RET_ADDR macro which
     26 * This file contains the definition of the GET_RET_ADDR macro which
    2727 * is designed to contain the archecture/compiler specific hacks to
    2828 * determine the return-address from inside the malloc library.  With
     
    3939 * __builtin_return_address(0); with gcc version 2+ should give you a
    4040 * good start on building a hack for your box.
     41 *
     42 * NOTE: the hacks mentioned above were removed in favor of the GCC macro
     43 * __builtin_return_address(). Assumptions made in these hacks break for
     44 * recent GCC versions.
    4145 */
    4246
     
    4448#define __OM_RETURN_H__
    4549
    46 /*************************************/
    47 
    48 /* for Sun SparcStations with GCC */
    49 #if __sparc && __GNUC__ > 1
    50 
    51 /*
    52  * NOTE: %i7 seems to be more reliable than the [%fp+4] used by
    53  * __builtin_return_address.  [%fp+4] is on the stack however, meaning
    54  * it may be better -- less prone to be erased.  However, it produces
    55  * some bogus data -- it seems to return the last return-address or
    56  * something like that.
    57  *
    58  * Alexandre Oliva <oliva@dcc.unicamp.br> recently advised to change
    59  * the "=g" to a "=m".  If you are having problems, you may want to
    60  * return to the =g to see if it works.
    61  */
    62 #define GET_RET_ADDR(file)      asm("st %%i7,%0" : \
    63                                     "=m" (file) : \
    64                                     /* no inputs */ )
    65 
    66 #if 0
    67 
    68 /* this was the default however =g was recommended to be changed to =m */
    69 #define GET_RET_ADDR(file)      asm("st %%i7,%0" : \
    70                                     "=g" (file) : \
    71                                     /* no inputs */ )
    72 
    73 /*
    74  * This was what the gcc __builtin_return_address returned.  The above
    75  * versions worked better.  It is here for reference purposes only.
    76  */
    77 #define GET_RET_ADDR(file)      asm("ld [%%fp+4],%%o0; st %%o0,%0" : \
    78                                         "=g" (file) : \
    79                                         /* no inputs */ : \
    80                                         "o0")
    81 #endif
    82 
    83 #endif /* __sparc */
    84 
    85 /*************************************/
    86 
    87 /* for i[34]86 machines with GCC */
    88 #if __i386 && __GNUC__ > 1
    89 
    90 #define GET_RET_ADDR(file)      asm("movl 4(%%ebp),%%eax ; movl %%eax,%0" : \
    91                                     "=g" (file) : \
    92                                     /* no inputs */ : \
    93                                     "eax")
    94 
    95 #endif /* __i386 */
    96 
    97 /*************************************/
    98 
    99 /*
    100  * For DEC Mips machines running Ultrix
    101  */
    102 #if __mips
    103 
    104 /*
    105  * I have no idea how to get inline assembly with the default cc.
    106  * Anyone know how?
    107  */
    108 
    109 #if 0
    110 
    111 /*
    112  * NOTE: we assume here that file is global.
    113  *
    114  * $31 is the frame pointer.  $2 looks to be the return address but maybe
    115  * not consistently.
    116  */
    117 #define GET_RET_ADDR(file)      asm("sw $2, file")
    118 
    119 #endif
    120 
    121 #endif /* __mips */
    122 
    123 /******************************* contributions *******************************/
    124 
    125 /*
    126  * For DEC Alphas running OSF.  from Dave Hill <ddhill@zk3.dec.com>
    127  * and Alexandre Oliva <oliva@dcc.unicamp.br>.  Thanks guys.
    128  */
    129 #if __alpha
    130 
    131 #ifdef __GNUC__
    132 
    133 #define GET_RET_ADDR(file)      asm("bis $26, $26, %0" : "=r" (file))
    134 
    135 #else /* __GNUC__ */
    136 
    137 #include <c_asm.h>
    138 
    139 #define GET_RET_ADDR(file)      file = (char *)asm("bis %ra,%ra,%v0")
    140 
    141 #endif /* __GNUC__ */
    142 
    143 #endif /* __alpha */
    144 
    145 /*************************************/
    146 
    147 /*
    148  * For Data General workstations running DG/UX 5.4R3.00 from Joerg
    149  * Wunsch <joerg_wunsch@julia.tcd-dresden.de>.
    150  */
    151 #ifdef __m88k__
    152 
    153 /*
    154  * I have no ideas about the syntax of Motorola SVR[34] assemblers.
    155  * Also, there may be occasions where gcc does not set up a stack
    156  * frame for some function, so the returned value should be taken with
    157  * a grain of salt. For the ``average'' function calls it proved to be
    158  * correct anyway -- jw
    159  */
    160 #if !__DGUX__ || _DGUXCOFF_TARGET
    161 # define M88K_RET_ADDR  "ld %0,r30,4"
    162 #else  /* __DGUX__ && !_DGUXCOFF_TARGET: DG/UX ELF with version 3 assembler */
    163 # define M88K_RET_ADDR  "ld %0,#r30,4"
    164 #endif
    165 
    166 #define GET_RET_ADDR(file)      asm(M88K_RET_ADDR : \
    167                                     "=r" (file) : \
    168                                     /* no inputs */)
    169 
    170 #endif /* m88k */
    171 
    172 /*************************************/
    173 
    174 /*
    175  * SGI compilers implement a C level method of accessing the return
    176  * address by simply referencing the __return_address symbol. -- James
    177  * Bonfield <jkb@mrc-lmb.cam.ac.uk>
    178  */
    179 #if defined(__sgi)
    180 
    181 #define GET_RET_ADDR(file)      file = (void *)__return_address
    182 
    183 #endif /* __sgi */
    184 
    185 /*************************************/
    186 
    187 /*
    188  * Stratus FTX system (UNIX_System_V 4.0 FTX release 2.3.1.1 XA/R
    189  * Model 310 Intel i860XP processor)
    190  *
    191  * I ended up with compiling according to full-ANSI rules (using the
    192  * -Xa compiler option).  This I could only do after modifying the
    193  * "dmalloc.h.3" in such a way that the malloc/calloc/realloc/free
    194  * definitions would no longer cause the compiler to bark with
    195  * 'identifier redeclared' (I just put an #ifdef _STDLIB_H ... #endif
    196  * around those functions).  -- Wim_van_Duuren@stratus.com
    197  */
    198 #if defined(_FTX) && defined(i860)
    199 
    200 /*
    201  * we first have the define the little assembly code function
    202  */
    203 asm void ASM_GET_RET_ADDR(file)
    204 {
    205 %       reg     file;
    206         mov     %r1, file
    207 %       mem     file;
    208         st.l    %r31,-40(%fp)
    209         orh     file@ha, %r0, %r31
    210         st.l    %r1, file@l(%r31)
    211         ld.l    -40(%fp),%r31
    212 %       error
    213 }
    214 #define GET_RET_ADDR(file)      ASM_GET_RET_ADDR(file)
    215 
    216 #endif /* _FTX & i860 */
    217 
    218 /*************************************/
    219 
    220 /*
    221  * For HP-UX PA-RISC with gcc/g++ from Jack Perdue
    222  * <j-perdue@tamu.edu>.
    223  */
    224 #if __hpux && __hppa && __GNUC__ > 1
    225 
    226 /*
    227  * This is my very first line of PA-RISC assembly ever.  I have no
    228  * idea if is correct, but it seems to work.  Register 2 (%r2)
    229  * contains the return address.  The code generated by x =
    230  * __builtin_return_address() was considerably longer and without a
    231  * PA-RISC Instruction Set guide available (not even on the web), I
    232  * just put togther little tidbits of knowledge I found while looking
    233  * for one to take a stab with this.  Like I said, it seems to work on
    234  * my g++ code under HPUX11 on a HP V-class system.  YMMV. -- Jack
    235  * Perdue (j-perdue@tamu.edu)
    236  */
    237 #define GET_RET_ADDR(file)  asm("stw %%r2, %0" : "=m" (file) :  );
    238 
    239 #endif
    240 
    241 /*************************************/
    242 
    243 /*
    244  * For Powerpc 603 based system running LynxOS 2.3.1 using gcc/gas.
    245  * From Shawn Carey <smc@questra.com>.
    246  */
    247 #if defined(__powerpc__) && defined(__GNUC__) && !defined(__OPTIMIZE__)
    248 
    249 /*
    250  * This won't compile if "-O2" is used, but it seems to work fine with
    251  * "-O0".  I'm no assembler expert; I was happy enough to come up with
    252  * something that works at all...  :-)
    253  */
    254 
    255 #define GET_RET_ADDR(file) \
    256 do { \
    257   asm("mflr 0"); \
    258   asm("stw 0,%0" : "=g" (file)); \
    259 } while(0)
    260 
    261 #endif /* __powerpc__ && __GNUC__ && !__OPTIMIZE__ */
    262 
    263 /*************************************/
    26450
    26551/********************************** default **********************************/
    266 
    267 /* for all others, do nothing */
    26852#ifndef GET_RET_ADDR
    26953
Note: See TracChangeset for help on using the changeset viewer.