Prevent the user defining non-static functions in more than one object file

Create issue
Issue #1553 duplicate
Ian Hinder created an issue

If a non-static function is defined in more than one object file, the results at run-time are unexpected or unpredictable. I was under the impression that there were compiler options to prevent this. At least on Mac OS, these must not be used, as I just ran into this problem.

So, either we find out which options are needed and add them, or we could provide some additional checks in the build system to help catch this error. For example, Cactus scheduled functions defined with the same name should be easy to catch.

Keyword:

Comments (3)

  1. Erik Schnetter
    • removed comment

    This is a problem because we put thorn functions into libraries, and (by default) libraries can contain duplicate definitions. In this case, the linker uses the first definition it sees, which depends on the order in which we list the thorns when calling the linker.

    We have modifications to the flesh that make Cactus use all functions from all thorns all the time. This leads to linker errors for duplicate functions. Since this is system-specific, this is not the default. (I am unaware of a system where this fails, though.)

    For OS X, you enable this with the options

    CACTUSLIBLINKLINE         = -L$(CCTK_LIBDIR) -filelist $(CCTK_LIBDIR)/LINKLIST,$(TOP)/build
    BEGIN_WHOLE_ARCHIVE_FLAGS = -L$(CCTK_LIBDIR)   # must not be empty
    END_WHOLE_ARCHIVE_FLAGS   =
    
  2. Ian Hinder reporter
    • removed comment

    Thanks; that works. I propose that this is added to the darwin known_architectures file so that it applies to all Mac OS systems. I have tested the attached patch and it works on Mac OS 10.8.5 (Mountain Lion) with the current SimFactory osx-mountain-lion-macports-gcc.cfg optionlist. [Aside: I have a long-term goal of eliminating the OS (as opposed to machine) optionlists in favour of auto-detecting everything in either the ExternalLibraries thorns or the known_architectures files. This is why I don't want to just add this to the existing OS X optionlist.]

  3. Log in to comment