lua-users home
lua-l archive

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


Am 23.11.18 um 06:47 schröbte Sean Conner:

[...]

	5.1.1.2:

	8 All external object and function references are resolved.  Library
	  components are linked to satisfy external references to functions
	  and objects not defined in the current translation.  All such
	  translator output is collected into a program image which contains
	  information needed for execution in its execution environment.

   I interpret this to mean, "if the given object files do not include an
object or function with external linkage, then said objects or functions can
be pulled from a "library".

Which library if there were multiple ones containing the same external definition?

I interpret it differently. I think "translation" still means the translation of a single translation unit (i.e. a single object file) as in all other translation phases before. So you resolve as many undefined external references in the object file as you can using libraries, and the remaining ones are resolved from other compiled translation units when "all such translator output is collected into a program image".

Anyway, the effect is exactly the same as with your interpretation as long as "In the set of translation units and libraries that constitutes an entire program, each declaration of a particular identifier with external linkage denotes the same object or function" (6.2.2) and "somewhere in the entire program there shall be exactly one external definition for the identifier; otherwise, there shall be no more than one" (6.9.5).


Btw., GNU ld is in violation of your interpretation of the C standard as I have shown in one of my examples earlier (details here[99]):

    $ gcc -o main main.c a.o -L. -lb
    ./libb.a(b.o): In function `a':
    b.c:(.text+0x0): multiple definition of `a'
    a.o:a.c:(.text+0x0): first defined here
collect2: error: ld returned 1 exit status

Function `a()` shouldn't have been pulled from `libb.a` because `a.o` already contains an external definition for that identifier.

GNU ld doesn't pull individual functions or objects from the library. It just filters out those object files in the library that it thinks it doesn't need.


[...]

   -spc (If at this point you don't think this interpretation holds, I'd like to
	hear the argument against it)


Philipp

  [99]:  http://lua-users.org/lists/lua-l/2018-11/msg00258.html