| Summary: | malloc fails in OMAGIC programs | ||
|---|---|---|---|
| Product: | Base System | Reporter: | dm <dm> |
| Component: | kern | Assignee: | freebsd-bugs (Nobody) <bugs> |
| Status: | Closed FIXED | ||
| Severity: | Affects Only Me | ||
| Priority: | Normal | ||
| Version: | 3.3-RELEASE | ||
| Hardware: | Any | ||
| OS: | Any | ||
<<On Sat, 18 Dec 1999 18:31:15 -0500 (EST), dm@reeducation-labor.lcs.mit.edu said: > % cc -static -N -o badomagic badomagic.c > % ./badomagic > malloc failed > Cannot allocate memory It appears that either malloc or execve is getting confused by the fact that the entire program is in a single load segment. Unless you demonstrate that this can cause a panic, I suspect the answer is ``don't do that, then''. For comparison: wollman@khavrinen$ cc -static -N foo.c wollman@khavrinen$ ./a.out malloc failed \^@Cannot allocate memory wollman@khavrinen$ cc -static -N -aout foo.c wollman@khavrinen$ ./a.out bash: ./a.out: cannot execute binary file -GAWollman -- Garrett A. Wollman | O Siem / We are all family / O Siem / We're all the same wollman@lcs.mit.edu | O Siem / The fires of freedom Opinions not those of| Dance in the burning flame MIT, LCS, CRS, or NSA| - Susan Aglukark and Chad Irschick This looks like a toolchain problem somehow:
173 ktrace RET ktrace 0
173 ktrace CALL execve(0xbfbffd6f,0xbfbffcb0,0xbfbffcb8)
173 ktrace NAMI "./a"
173 a RET execve 0
173 a CALL readlink(0x804a6d4,0xbfbffbb4,0x3f)
173 a NAMI "/etc/malloc.conf"
173 a RET readlink -1 errno 2 No such file or directory
173 a CALL mmap(0,0x1000,0x3,0x1002,0xffffffff,0,0,0)
173 a RET mmap 536870912/0x20000000
173 a CALL break(0x804c000)
173 a RET break -1 errno 12 Cannot allocate memory
syv# !107
cc -static -N -o a a.c
syv# nm -n a | head
U _DYNAMIC
08048074 ? _init
0804807c T _start
08048160 t gcc2_compiled.
08048160 T main
08048234 T atexit
080482e4 T strlen
080482fc W __error
080482fc T __error_unthreaded
08048310 T _write
[...]
I thought programs started out at 0x0 or at least close to zero ?
--
Poul-Henning Kamp FreeBSD coreteam member
phk@FreeBSD.ORG "Real hackers run -current on their laptop."
FreeBSD -- It will take a long time before progress goes too far!
State Changed From-To: open->closed Antique PR. |
Memory allocation files in OMAGIC programs. Fix: unknown How-To-Repeat: Compile and run this program: #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <string.h> int main (int argc, char **argv) { char *p = malloc (8192); if (!p) { char badmalloc[] = "malloc failed\n"; write (2, badmalloc, sizeof (badmalloc)); write (2, strerror (errno), strlen (strerror (errno))); write (2, "\n", 1); exit (1); } exit (0); } /* --- end --- */ like this: % cc -static -N -o badomagic badomagic.c % ./badomagic malloc failed Cannot allocate memory %