Re: ports/bash4 --enable-static fails

2012-05-10 Thread Chet Ramey
On 5/10/12 12:20 AM, Craig Rodrigues wrote:

> Bash is trying to override the malloc() functions in libc with its own
> implementation in lib/malloc/malloc.c .
> I have seen this type of trick before 3rd party code that tries to
> override the libc implementation of malloc() / free() with its own.
> 
> kan@ explained this to me before, but I don't know if I can explain it
> as well as him, because it has to do
> with how static linking works. :)
> 
> Basically, the malloc.o object from bash, *must* have implementations of
> *all* the relevant functions in jemalloc_jemalloc.o in order for
> malloc.o to properly override jemalloc_jemalloc.o.
> 
> If you have something like:
> jemalloc_jemalloc.o  (libc)   malloc.o (Bash)
> ===   =
> malloc()  malloc()
> free()   free()
> calloc()
> realloc()
> 
> 
> the static linker will not be able to replace jemalloc_jemalloc.o from
> libc with malloc.o from Bash,
> because calloc() and realloc() symbols in jemalloc_jemalloc.o (libc)
> do not exist malloc.o (Bash).
> 
> Since the linker can only deal with whole objects (.o files), it will
> try to pull in both
> jemalloc_jemalloc.o and malloc.o when doing static linking.
> 
> I may have got some of the details/explanation wrong, but I have fixed
> something similar
> to this in 3rd party code, when the layout of malloc() functions in
> libc changed between FreeBSD 4 and FreeBSD 6.

This explanation is substantially correct.

> 
> What you need to do is:
>(1)  run nm or readelf on jemalloc_jemalloc.o,   then run nm or
> readelf on malloc.o
>(2)  Look at the symbols in both
>(3)  Add the missing symbols to malloc.c in Bash

The bash malloc includes definitions for malloc/free/realloc/calloc/cfree/
valloc/memalign.  I'd be interested in knowing what other global symbols
jemalloc exports.  I'd also be interested in seeing how someone managed to
compile the bash malloc and leave out realloc.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/
___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"


Re: Shell programming 101: Is this an expr(1) bug ?

2003-02-18 Thread Chet Ramey
> Running:
> 
>   #!/bin/sh
>   set -ex
> 
>   for p in ad2 ad0 ad1
>   do
>   a0=`expr $p : '^ad\([0-9]\)$'`
>   done
> 
> I get:
> 
>   syv# sh _
>   + expr ad2 : ^ad\([0-9]\)$
>   + a0=2
>   + expr ad0 : ^ad\([0-9]\)$
>   + a0=0
>   syv# echo $?
>   1

The `set -e' says to exit the shell if a simple command fails.  POSIX.2
says that the exit status of an assignment statement without an accompanying
command is either 0 or the exit status of the last command substitution
performed while expanding the rhs.  `expr' returns 1 when the result is
`0'.  Thus the assignment statement fails and the shell exits.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet )

Chet Ramey, ITS, CWRU[EMAIL PROTECTED]http://cnswww.cns.cwru.edu/~chet/

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message