[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ld: global symbol warning message suggestion

From: Jari Lappalainen
Subject: ld: global symbol warning message suggestion
Date: Tue, 6 Jul 2004 14:58:48 +0300


I have an object file with a global variable 'bind'. I have linked 
the file to an application which uses libc function 'bind'. 
The linking goes fine, but when run, the application experiences 
segmentation fault on function 'bind'.

If the crash results from the two names being mixed, perhaps a warning 
message could be issued from ld.

I have tried using --warn-common but it seems it doesn't give warnings 
with these types of symbol name errors.

Version info:
gcc: gcc (GCC) 3.3.2 (Mandrake Linux 10.0 3.3.2-6mdk)
ld: GNU ld version 20031029
uname: Linux 2.6.3-4mdk

Thank you for considering my suggestion,

        Jari Lappalainen

The following is a small example of the condition.

==== file blib.h ====

void libfunction();

==== file blib.c ====

int bind;

void libfunction()

==== file bind.c ====

#include "blib.h"
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>

make_socket (uint16_t port)
  int sock;
  struct sockaddr_in name;

  /* Create the socket. */
  sock = socket (PF_INET, SOCK_STREAM, 0);
  if (sock < 0)
      perror ("socket");
      return -1;

  /* Give the socket a name. */
  name.sin_family = AF_INET;
  name.sin_port = htons (port);
  name.sin_addr.s_addr = htonl (INADDR_ANY);
  printf("%d\n", __LINE__);
  int rc = bind (sock, (struct sockaddr *) &name, sizeof (name));
  printf("%d\n", __LINE__);
  if (rc < 0)
      perror ("bind");
      return -1;

  return sock;

  return 0;

==== Compile and link with ====

$ gcc -W -Wall -c blib.c
$ gcc -W -Wall -c bind.c
$ gcc -W -Wall bind.o blib.o

Running this with 

$ ./a.out

shows segmentation fault in function bind.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]