[parisc-linux] Constructor not run in 3.3.3, but does run in 3.0.4

Carlos O'Donell carlos at baldric.uwo.ca
Fri Jan 30 14:23:36 MST 2004


jda,

I'm playing with a new glibc, it has the new port to generic function
descriptors...

I have a test application whose 'init' is not being run. The application
has a number of DSO it depends on, and as each DSO loads it prints a
number from its 'init', and as it unloads it prints a number from its
'fini'. The main executable doesn't run its 'init', but does run the
'fini'.

In glibc during dl-init() the loader skips running lt_type == lt_executable
'init' functions. The comment notes that it doesn't have to do that job.
Is this the job of the compiler?

---
#include <unistd.h>

void init (void) __attribute__ ((constructor));
void
__attribute__ ((constructor))
init (void)
{
  write (1, "4", 1);
}

void fini (void) __attribute__ ((destructor));
void
__attribute__ ((destructor))
fini (void)
{
  write (1, "5", 1);
}

extern int dep1 (void); 

int
main (void)
{
  return dep1 () != 42;
}
---

An example of the DSO that is loaded...
---
#include <unistd.h>

extern int dep3 (void); 

static void
__attribute__ ((constructor))
init (void)
{
  write (1, "0", 1);
}

static void
__attribute__ ((destructor))
fini (void)
{
  write (1, "9\n", 2);
}

int
dep3 (void)
{
  return 42;
}
---


When all is said and done it should print '0123456789', but right now it
prints '012356789', skipping '4'. If I compile with gcc-3.0.4 it
complains about:
/home/carlos/src/glibc-work/src/libc/include/unistd.h:71: warning:
`visibility' attribute directive ignored

69 char *__canonicalize_directory_name_internal (__const char *__thisdir,
70                                               char *__buf,
71                                               size_t __size) attribute_hidden;

Seems like a red-herring. However, with gcc-3.0.4 everything works just
fine. The order of the initializers is back to normal.

Is there any fragile system by which the linker finds and labels the
executables 'init'?

c.



More information about the parisc-linux mailing list