cpp crash with gcc-2.95.2 and cpplib

Niels M=f6ller nisse@ehand.com
Mon Dec 11 07:09:00 GMT 2000


Hi,

I originally encountered this bug with John's patched gcc
(prc-tools-2.0), however, the bug is present also in the plain
gcc-2.95.2, when compiled with --enable-cpplib.

The command line that triggers the bug (taken from m68k-palmos-gcc -v,
but with some extra quotes, so that it can be started fromt he shell
or from gdb, and with the cpp program replaced with the system's normal
cpp):

  jekyll:~/build/prc-tools-2.0$ /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/cpp -lang-c -I/usr/local/src/prc-tools-2.0/libc/include -I/usr/local/src/prc-tools-2.0/libc/../crt -D__GNUC__=2 -D__GNUC_MINOR__=95 -Dm68000 -Dmc68000 -Dm68k -D__palmos__ -D__m68000__ -D__mc68000__ -D__m68k__ -D__palmos__ -D__m68000 -D__mc68000 -D__m68k '-Asystem(palmos)' '-Acpu(m68k)' '-Amachine(pilot)' -D__OPTIMIZE__ -Wall -Dmc68000 -D__mc68000 -D__mc68000__ -isystem /usr/local/palmdev/include -isystem /usr/local/palmdev/sdk-3.5/include/Core/System -isystem /usr/local/palmdev/sdk-3.5/include/Core/UI -isystem /usr/local/palmdev/sdk-3.5/include -isystem /usr/local/palmdev/sdk-3.5/include/Core -isystem /usr/local/palmdev/sdk-3.5/include/Core/Hardware -isystem /usr/local/palmdev/sdk-3.5/include/Core/System/Unix -remap -DPRINT_FLOATS -DSDK_VERSION=35 -DLmalloc /usr/local/src/prc-tools-2.0/libc/malloc.c /tmp/cc6cix17.i
  Segmentation fault (core dumped)

Source file appended below. I apologize for the missing includes; they
are from the Palmos sdk-3.5. 

The preprocessor is

  jekyll:~/build/prc-tools-2.0$ /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/cpp --version
  cpp: GNU CPP version 2.95.2 19991024 (release)

built from the plain gcc-2.95.2 sources with

  /usr/local/src/gcc-2.95.2/configure --enable-cpplib && make bootstrap

Looking at cpp in gdb, I get the following backtrace:

  #0  0x8052029 in remap_filename (pfile=0x805b5a0, 
      name=0x8060668 "/usr/local/palmdev/sdk-3.5/include/System/SysUtils.h", 
      loc=0x805d1c8) at /usr/local/src/gcc-2.95.2/gcc/cppfiles.c:594
  #1  0x8051ac5 in find_include_file (pfile=0x805b5a0, 
      fname=0xbffff715 "System/SysUtils.h", search_start=0x8061088, 
      ihash=0xbffff764, before=0xbffff768)
      at /usr/local/src/gcc-2.95.2/gcc/cppfiles.c:376
  #2  0x804a476 in do_include (pfile=0x805b5a0, keyword=0x805ac5c)
      at /usr/local/src/gcc-2.95.2/gcc/cpplib.c:1101
  #3  0x8049a48 in handle_directive (pfile=0x805b5a0)
      at /usr/local/src/gcc-2.95.2/gcc/cpplib.c:545
  #4  0x804ba6c in cpp_get_token (pfile=0x805b5a0)
      at /usr/local/src/gcc-2.95.2/gcc/cpplib.c:2132
  #5  0x8048fdd in main (argc=45, argv=0xbffff884)
      at /usr/local/src/gcc-2.95.2/gcc/cppmain.c:86

The crash happens in cppfiles.s:remap_filename().

    for (map = read_name_map (pfile, dir); map; map = map->map_next)
=>    if (! strcmp (map->map_from, name))
        return map->map_to;

The variable MAP seems to get a bogus value,

  (gdb) p map
  $2 = (struct file_name_map *) 0xffffffff

To me, it seems that -remap flag (which is present in the specs file
for the prc-tools cross-compiler, but not in the specs for the vanilla
compiler), is broken. I don't know what it is supposed to do or why it
is needed.

Best regards,
/Niels

/* C support library memory management functions for Palm OS.

   Author: John Marshall  (They're not very complicated :-))

   This code is in the public domain.  */

#include "stdlib.h"

#include <MemoryMgr.h>
#include "sdktypes.h"

#ifdef Lmalloc

void *
malloc (size_t size) {
  return MemPtrNew (size);
  }

#endif
#ifdef Lfree

void
free (void *ptr) {
  if (ptr)  MemPtrFree (ptr);
  }

#endif
#ifdef Lcalloc

void *
calloc (size_t nmemb, size_t memb_size) {
  UInt32 size = nmemb * memb_size;
  void *ptr = MemPtrNew (size);
  if (ptr)
    MemSet (ptr, size, 0);
  return ptr;
  }

#endif
#ifdef Lrealloc

void *
realloc (void *ptr, size_t size) {
  if (ptr == NULL)
    return MemPtrNew (size);
  else if (size == 0) {
    if (ptr)  MemPtrFree (ptr);
    return NULL;
    }
  else if (MemPtrResize (ptr, size) == 0)
    return ptr;
  else {
    void *newptr = MemPtrNew (size);
    if (newptr) {
      /* We must copy min(oldsize,newsize) bytes; since MemPtrResize always
	 succedes when shrinking, the old size is always the minimum.  */
      MemMove (newptr, ptr, MemPtrSize (ptr));
      MemPtrFree (ptr);
      }
    return newptr;
    }
  }

#endif


More information about the Gcc-bugs mailing list