public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Help on -nodefaultlibs
@ 2002-08-26 17:42 Yong Jiang
  2002-08-27  0:29 ` Der Herr Hofrat
  0 siblings, 1 reply; 2+ messages in thread
From: Yong Jiang @ 2002-08-26 17:42 UTC (permalink / raw)
  To: help-gcc

Hi,

We are planning to write some drivers that are independent from both OS and
hardware platforms, since these drivers will be written by many people and will
be shared by multiple platforms in source level, it is good that if some kind
of 'generic' code checking can be done at the time these drivers are put in
place. Specificly, one of the things i would like to check is that these
drivers can only use data types and functions that are defined in the driver
code, no OS or platform specific data or functions can be used. I would like to
run the gcc in SunUnix environment in a way that no library is provided and
it will complain if not every function is fully defined in the source. So it
looks like the -nodefaultlibs link option serves what I need, but it gave me
lots of errors when I tried it. Can any one give me a help on this? Thanks.

Example:

a simple program:
int main()
{
  int x;
  x = 1;
  return(0);
}

compiled:
gcc -nodefaultlibs -lgcc main.c

got the errors attached in the end of this email...

* and I would want this:
if I compile the following program it should complain 'printf', 'malloc' and
sprintf not defined(and no other errors beside these):
int main()
{
  char *ptr;

  ptr = (char *)malloc(10);
  sprintf(ptr, "hello");
  printf("%s\n", ptr);

  return(0);
}



======== attached compilation errors for the first example program ============
yjiang-u5:/users/yjiang/yjiang/temp_c/chk> gcc -nodefaultlibs -lgcc main.c
/sw/packages/cygnus/progressive-98r1-v0/H-sparc-sun-solaris2.6/bin/../lib/gcc-li
b/sparc-sun-solaris2.6/2.9-cisco-98r1/crt1.o: In function `_start':
/sw/packages/cygnus/progressive-98r1-v0/H-sparc-sun-solaris2.6/bin/../lib/gcc-li
b/sparc-sun-solaris2.6/2.9-cisco-98r1/crt1.o(.text+0x1c): undefined reference to
 `atexit'
/sw/packages/cygnus/progressive-98r1-v0/H-sparc-sun-solaris2.6/bin/../lib/gcc-li
b/sparc-sun-solaris2.6/2.9-cisco-98r1/crt1.o(.text+0x2c): undefined reference to
 `atexit'
/sw/packages/cygnus/progressive-98r1-v0/H-sparc-sun-solaris2.6/bin/../lib/gcc-li
b/sparc-sun-solaris2.6/2.9-cisco-98r1/crt1.o(.text+0x50): undefined reference to
 `_environ'
/sw/packages/cygnus/progressive-98r1-v0/H-sparc-sun-solaris2.6/bin/../lib/gcc-li
b/sparc-sun-solaris2.6/2.9-cisco-98r1/crt1.o(.text+0x54): undefined reference to
 `_environ'
/sw/packages/cygnus/progressive-98r1-v0/H-sparc-sun-solaris2.6/bin/../lib/gcc-li
b/sparc-sun-solaris2.6/2.9-cisco-98r1/crt1.o(.text+0x64): undefined reference to
 `exit'
/sw/packages/cygnus/progressive-98r1-v0/H-sparc-sun-solaris2.6/bin/../lib/gcc-li
b/sparc-sun-solaris2.6/2.9-cisco-98r1/crt1.o(.text+0x6c): undefined reference to
 `_exit'
/sw/packages/cygnus/progressive-98r1-v0/H-sparc-sun-solaris2.6/bin/../lib/gcc-li
b/sparc-sun-solaris2.6/2.9-cisco-98r1/libgcc.a(frame.o): In function `frame_init
':
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c(.text+0x230):
undefined reference to `malloc'
/sw/packages/cygnus/progressive-98r1-v0/H-sparc-sun-solaris2.6/bin/../lib/gcc-li
b/sparc-sun-solaris2.6/2.9-cisco-98r1/libgcc.a(frame.o): In function `extract_ci
e_info':
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c(.text+0x450):
undefined reference to `strcmp'
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c(.text+0x470):
undefined reference to `strcmp'
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c(.text+0x4a4):
undefined reference to `strlen'
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c(.text+0x4c0):
undefined reference to `strcmp'
/sw/packages/cygnus/progressive-98r1-v0/H-sparc-sun-solaris2.6/bin/../lib/gcc-li
b/sparc-sun-solaris2.6/2.9-cisco-98r1/libgcc.a(frame.o): In function `execute_cf
a_insn':
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c(.text+0x56c):
undefined reference to `umul'
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c(.text+0x5ac):
undefined reference to `umul'
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c:436: undefined
 reference to `umul'
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c:477: undefined
 reference to `malloc'
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c:480: undefined
 reference to `memcpy'
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c:487: undefined
 reference to `memcpy'
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c:488: undefined
 reference to `free'
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c:507: undefined
 reference to `abort'
/sw/packages/cygnus/progressive-98r1-v0/H-sparc-sun-solaris2.6/bin/../lib/gcc-li
b/sparc-sun-solaris2.6/2.9-cisco-98r1/libgcc.a(frame.o): In function `__register
_frame':
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c:534: undefined
 reference to `malloc'
/sw/packages/cygnus/progressive-98r1-v0/H-sparc-sun-solaris2.6/bin/../lib/gcc-li
b/sparc-sun-solaris2.6/2.9-cisco-98r1/libgcc.a(frame.o): In function `__register
_frame_table':
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c:562: undefined
 reference to `malloc'
/sw/packages/cygnus/progressive-98r1-v0/H-sparc-sun-solaris2.6/bin/../lib/gcc-li
b/sparc-sun-solaris2.6/2.9-cisco-98r1/libgcc.a(frame.o): In function `__deregist
er_frame_info':
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c:585: undefined
 reference to `free'
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c:594: undefined
 reference to `abort'
/sw/packages/cygnus/progressive-98r1-v0/H-sparc-sun-solaris2.6/bin/../lib/gcc-li
b/sparc-sun-solaris2.6/2.9-cisco-98r1/libgcc.a(frame.o): In function `__deregist
er_frame':
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c:600: undefined
 reference to `free'
/sw/packages/cygnus/progressive-98r1-v0/H-sparc-sun-solaris2.6/bin/../lib/gcc-li
b/sparc-sun-solaris2.6/2.9-cisco-98r1/libgcc.a(frame.o): In function `__frame_st
ate_for':
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c:623: undefined
 reference to `memset'
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c:647: undefined
 reference to `memcpy'
collect2: ld returned 1 exit status



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Help on -nodefaultlibs
  2002-08-26 17:42 Help on -nodefaultlibs Yong Jiang
@ 2002-08-27  0:29 ` Der Herr Hofrat
  0 siblings, 0 replies; 2+ messages in thread
From: Der Herr Hofrat @ 2002-08-27  0:29 UTC (permalink / raw)
  To: Yong Jiang; +Cc: help-gcc

> Hi,
> 
> We are planning to write some drivers that are independent from both OS and
> hardware platforms, since these drivers will be written by many people and will
> be shared by multiple platforms in source level, it is good that if some kind
> of 'generic' code checking can be done at the time these drivers are put in
> place. Specificly, one of the things i would like to check is that these
> drivers can only use data types and functions that are defined in the driver
> code, no OS or platform specific data or functions can be used. I would like to
> run the gcc in SunUnix environment in a way that no library is provided and
> it will complain if not every function is fully defined in the source. So it
> looks like the -nodefaultlibs link option serves what I need, but it gave me
> lots of errors when I tried it. Can any one give me a help on this? Thanks.
> 
> Example:
> 
> a simple program:
> int main()
> {
>   int x;
>   x = 1;
>   return(0);
> }
> 
> compiled:
> gcc -nodefaultlibs -lgcc main.c
>
I assume the answer depends on the glibc version you are using but you need 
more than only libgcc linked in even for the above example as gcc may use
memset, memcpy and a few other functions to initialize things which are in
libc - so you probably need to supplie a -lc as a minimum (see info gcc 
"Options for Linking"). Also if you are trying to link to a libc that is
not the system default then the header files must also fit (in the above
example this may be irrelevant though).

here is an example makefile I use on a glibc-2.2.X system to link with 
glibc-2.0.7 -

hofrat


---Makefile---
all:	hello

#
# Set this to your glibc copy or pass it on the command line
#
ifndef GLIBC_DEVEL
   GLIBC_DEVEL=/usr/src/your_devel_lib
endif

#
# exlicildy list libraries required
#
LIBRARIES = -lc 
GCCINCDIR = $(shell gcc -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp")
GLIBC_CFLAGS+=-nostdinc -I$(GLIBC_DEVEL)/include -I$(GCCINCDIR) -s

#
# set this to fit your target system
#
CFLAGS = -mcpu=i386 \
         -msoft-float \
         $(GLIBC_CFLAGS) 
LDFLAGS+= -nodefaultlibs \
          -L$(GLIBC_DEVEL)/lib \
          -Wl,-rpath-link,$(GLIBC_DEVEL)/lib \
          $(LIBRARIES)

hello:	hello.c

clean:
	rm -f core *.o hello

.c.o:
	$(CC) -Wall $(CFLAGS) $(LDFLAGS) -o $@ -c $<

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-08-27  7:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-26 17:42 Help on -nodefaultlibs Yong Jiang
2002-08-27  0:29 ` Der Herr Hofrat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).