[PATCH v2 xserver] os,dix: rename *.O to *.a

Mihail Konev k.mvc at ya.ru
Fri Feb 10 23:15:19 UTC 2017


Log of searching for "ld -r" attached, in case it is of any help.

On Fri, Feb 10, 2017 at 10:47:29AM +0500, Mihail Konev wrote:
> 
> The dtrace-in-a-separate-dir is preferrable, IMO:
> - allows for another dtrace-like additional-objects-compiler
> - cleaner makefile
> - simpler diff
> 

Really no difference.
While it would be indeed more straightforward to not have
libos_dtraced.la, this could be as well archieved with

  libos_la_LIBADD=
  if SPECIAL_DTRACE_OBJECTS
    libos_la_LIBADD += dtrace.a
  endif
  if ANOTHER_OBJECTS
    libos_la_LIBADD += another.a
  fi

So it is just of preference, whether to use some misc/ top-level
subdir for dtrace or just leave it in-line as it is now.

Mihail
-------------- next part --------------
Built 058809c43ec578a407cf40d4c3e54a42503e3562 as:
  ./configure --enable-dmx,
  with /usr/bin/dtrace being present (from the systemtap)

It suceeds.

Saved the output of:
  rm hw/dmx/Xdmx
  make -C hw/dmx Xdmx V=1 CFLAGS='-v'

Then built the same as:
  ./configure --enable-dmx --with-dtrace=no

It fails, as on a fresh Ubuntu 17.04, where systemtap
is not installed by default (HashGlyph cannot find x_sha1_init,
e.g. librender.a cannot find libos.a).

Noticed that in the /usr/bin/dtrace case, the librender does find
the os.O's x_sha1_init, even through the latter is put, by libtool,
in front of all other libraries (e.g. right after the dmx*.o files).

Ran the:
  rm os/.libs/libos.a
  make -C os libos.la V=1 CFLAGS='-v'

It shows that libos.a is created with 'ar cru', i.e. there is no linker involved.
(There also is 'ranlib', but it is just another form of 'ar' invocation).

Noticed that os.O is built with 'ld':
  ld -r -o $@ dtrace.o .libs/*.o

So there is the linker involved, and it is passed a '--relocatable' flag,
which puts it into under-documented "partial linking" mode.
(Neither 'info ld' nor google describe it).

Then took the collect2 invocation command from the output of the 'make Xdmx' for
successfull /usr/bin/dtrace case, and edited as:
  ../../os/os.O   -> ../../os.O1
  ../../dix/dix.O -> ../../dix.O1

Then created the O1 files:
  ld -r -o os.O1 os/.libs/*.o
  ld -r -o dix.O1 dix/.libs/*.o

Then ran the edited collect2 command line and it worked.

So the "ld -r" must be making symbols visible from an object for-the-following-libraries
on the linker command line, not only for-the-preceding-ones, as it is with
"ar cru"-ed foo.a and non-"ld -r"-ed -lbar.

Now, the "-r" was not explained, but could be assumed to be a workaround
for libtool's putting-os.O-in-front-of-all-else
("git log -L 68,68:os/Makefile.am"):

  commit 49a26681b2bdd95ed65c425f1fa1441d2f092a6e
  Author: Alan Coopersmith <alan.coopersmith at sun.com>
  Date:   Fri Nov 3 12:54:43 2006 -0800

      Add DTrace probe points for X server <-> client communications

      See http://people.freedesktop.org/~alanc/dtrace/ for more details

  diff --git a/os/Makefile.am b/os/Makefile.am
  --- a/os/Makefile.am
  +++ b/os/Makefile.am
  @@ -53,0 +62,1 @@
  +       ld -r -o $@ dtrace.o .libs/*.o

There are two solutions - either use os.O regardless of the dtrace presence and do

        ld -r -o $@ $(DTRACE_O_OR_NOTHING) .libs/*.o

or do not use "ld -r" at all and "ar cru" the .libs/libdix.a manually.

The latter seems to be less depending on ld capabilities, and thus, more portable.

Implementing it, however, reveals that the commit actually leaved dix.O intact, instead
putting both dix/dtrace.o and os/dtrace.o into the os.O.
This is required, as otherwise:

  diff --git a/dix/Makefile.am b/dix/Makefile.am
  index a4171d7e1f12..1094f331a722 100644
  --- a/dix/Makefile.am
  +++ b/dix/Makefile.am
  @@ -61,14 +61,14 @@ endif
   if SPECIAL_DTRACE_OBJECTS
   # Generate dtrace object code for probes in libdix
  -dtrace-dix.o: $(top_srcdir)/dix/Xserver.d libdix.la
  +dix-dtrace.o: $(top_srcdir)/dix/Xserver.d libdix.la
          $(AM_V_GEN)$(DTRACE) -G -C -o $@ -s $(top_srcdir)/dix/Xserver.d $(am_libdix_la_OBJECTS:%.lo=.libs/%.o)

   noinst_PROGRAMS = dix.O

   dix_O_SOURCES =
  -dix.O: dtrace-dix.o libdix.la
  -       $(AM_V_GEN)ld -r -o $@ $(am_libdix_la_OBJECTS:%.lo=.libs/%.o)
  +dix.O: dix-dtrace.o libdix.la
  +       $(AM_V_GEN)ld -r -o $@ $< $(am_libdix_la_OBJECTS:%.lo=.libs/%.o)
   endif

   CLEANFILES = Xserver-dtrace.h
  diff --git a/os/Makefile.am b/os/Makefile.am
  index c6e78cb99fd5..b61a331990a5 100644
  --- a/os/Makefile.am
  +++ b/os/Makefile.am
  @@ -58,12 +58,12 @@ EXTRA_DIST = $(SECURERPC_SRCS) $(XDMCP_SRCS)

   if SPECIAL_DTRACE_OBJECTS
   # Generate dtrace object code for probes in libos & libdix
  -dtrace.o: $(top_srcdir)/dix/Xserver.d libos.la
  -       $(AM_V_GEN)$(DTRACE) -G -C -o $@ -s $(top_srcdir)/dix/Xserver.d .libs/*.o ../dix/.libs/*.o
  +os-dtrace.o: $(top_srcdir)/dix/Xserver.d libos.la
  +       $(AM_V_GEN)$(DTRACE) -G -C -o $@ -s $(top_srcdir)/dix/Xserver.d .libs/*.o

   noinst_PROGRAMS = os.O

   os_O_SOURCES =
  -os.O: dtrace.o libos.la
  -       $(AM_V_GEN)ld -r -o $@ dtrace.o .libs/*.o
  +os.O: os-dtrace.o libos.la
  +       $(AM_V_GEN)ld -r -o $@ $< .libs/*.o
   endif

the following is seen:

  make[5]: Leaving directory '/home/m/xorg/xserver/hw/xfree86/dixmods'
  make[5]: Leaving directory '/home/m/xorg/xserver/hw/xfree86/dixmods'
  make[5]: Leaving directory '/home/m/xorg/xserver/hw/xfree86/i2c'
    CCLD     Xorg
  ../../os/os.O:(.probes+0xe): multiple definition of `Xserver_send__event_semaphore'
  ../../dix/dix.O:(.probes+0xe): first defined here
  ../../os/os.O: In function `__dtrace':
  /tmp/tmpAVuTN3.c:2: multiple definition of `Xserver_client__auth_semaphore'
  ../../dix/dix.O:/tmp/tmpWjUs1C.c:2: first defined here
  ../../os/os.O: In function `__dtrace':
  /tmp/tmpAVuTN3.c:2: multiple definition of `Xserver_resource__alloc_semaphore'
  ../../dix/dix.O:/tmp/tmpWjUs1C.c:2: first defined here
  ../../os/os.O: In function `__dtrace':
  /tmp/tmpAVuTN3.c:2: multiple definition of `Xserver_client__disconnect_semaphore'
  ../../dix/dix.O:/tmp/tmpWjUs1C.c:2: first defined here
  ../../os/os.O: In function `__dtrace':
  /tmp/tmpAVuTN3.c:2: multiple definition of `Xserver_request__start_semaphore'
  ../../dix/dix.O:/tmp/tmpWjUs1C.c:2: first defined here
  ../../os/os.O: In function `__dtrace':
  /tmp/tmpAVuTN3.c:2: multiple definition of `Xserver_resource__free_semaphore'
  ../../dix/dix.O:/tmp/tmpWjUs1C.c:2: first defined here
  ../../os/os.O: In function `__dtrace':
  /tmp/tmpAVuTN3.c:2: multiple definition of `Xserver_input__event_semaphore'
  ../../dix/dix.O:/tmp/tmpWjUs1C.c:2: first defined here
  ../../os/os.O: In function `__dtrace':
  /tmp/tmpAVuTN3.c:2: multiple definition of `Xserver_request__done_semaphore'
  ../../dix/dix.O:/tmp/tmpWjUs1C.c:2: first defined here
  ../../os/os.O: In function `__dtrace':
  /tmp/tmpAVuTN3.c:2: multiple definition of `Xserver_client__connect_semaphore'
  ../../dix/dix.O:/tmp/tmpWjUs1C.c:2: first defined here
  collect2: error: ld returned 1 exit status
  Makefile:804: recipe for target 'Xorg' failed
  make[4]: *** [Xorg] Error 1
  make[4]: Leaving directory '/home/m/xorg/xserver/hw/xfree86'
  Makefile:854: recipe for target 'all-recursive' failed
  make[3]: *** [all-recursive] Error 1
  make[3]: Leaving directory '/home/m/xorg/xserver/hw/xfree86'
  Makefile:669: recipe for target 'all' failed
  make[2]: *** [all] Error 2
  make[2]: Leaving directory '/home/m/xorg/xserver/hw/xfree86'
  Makefile:611: recipe for target 'all-recursive' failed
  make[1]: *** [all-recursive] Error 1
  make[1]: Leaving directory '/home/m/xorg/xserver/hw'
  Makefile:778: recipe for target 'all-recursive' failed
  make: *** [all-recursive] Error 1

So, add a new libdtrace.a.
To express the demand of it being built after os/ and dix/,
it must be made by a makefile in a subdirectory that follows them in SUBDIRS.
To satisfy the XSERVER_DTRACE #ifdef-ed code, it must be after dix and os in linker
command line.

There is (probably) no need to worry about it, as os.O and dix.O, being put in front of all else,
as "a non-libtool's *.la library", because, it seems, it was instead a subject to this as "an unknown extension library",
as there seems to be no reordering performed for "non-*.la" libdtrace.a when it is put into XORG/XDMX/XNEST/XVFB/XWAYLAND_LIBS
in the configure.ac (and KDRIVE_PURE_LIBS also).

If not put after dix and os, it gives:

  make[3]: Entering directory '/home/m/xorg/xserver/hw/vfb'
    CCLD     Xvfb
  ../../dix/.libs/libdix.a(dispatch.o): In function `Dispatch':
  /home/m/xorg/xserver/dix/dispatch.c:486: undefined reference to `Xserver_request__done_semaphore'
  /home/m/xorg/xserver/dix/dispatch.c:467: undefined reference to `Xserver_request__start_semaphore'
  /home/m/xorg/xserver/dix/dispatch.c:486: undefined reference to `Xserver_request__done_semaphore'
  /home/m/xorg/xserver/dix/dispatch.c:467: undefined reference to `Xserver_request__start_semaphore'
  ../../dix/.libs/libdix.a(dispatch.o):(.note.stapsdt+0x24): undefined reference to `Xserver_client__disconnect_semaphore'
  ../../dix/.libs/libdix.a(dispatch.o):(.note.stapsdt+0x74): undefined reference to `Xserver_request__done_semaphore'
  ../../dix/.libs/libdix.a(dispatch.o):(.note.stapsdt+0xe4): undefined reference to `Xserver_request__start_semaphore'
  ../../dix/.libs/libdix.a(events.o): In function `WriteEventsToClient':
  /home/m/xorg/xserver/dix/events.c:5955: undefined reference to `Xserver_send__event_semaphore'
  ../../dix/.libs/libdix.a(events.o):(.note.stapsdt+0x24): undefined reference to `Xserver_send__event_semaphore'
  ../../dix/.libs/libdix.a(getevents.o): In function `GetKeyboardEvents':
  /home/m/xorg/xserver/dix/getevents.c:1098: undefined reference to `Xserver_input__event_semaphore'
  ../../dix/.libs/libdix.a(getevents.o): In function `GetPointerEvents':
  /home/m/xorg/xserver/dix/getevents.c:1642: undefined reference to `Xserver_input__event_semaphore'
  ../../dix/.libs/libdix.a(getevents.o): In function `GetProximityEvents':
  /home/m/xorg/xserver/dix/getevents.c:1782: undefined reference to `Xserver_input__event_semaphore'
  ../../dix/.libs/libdix.a(getevents.o): In function `GetTouchEvents':
  /home/m/xorg/xserver/dix/getevents.c:1912: undefined reference to `Xserver_input__event_semaphore'
  ../../dix/.libs/libdix.a(getevents.o):(.note.stapsdt+0x24): undefined reference to `Xserver_input__event_semaphore'
  ../../dix/.libs/libdix.a(getevents.o):(.note.stapsdt+0x98): more undefined references to `Xserver_input__event_semaphore' follow
  ../../dix/.libs/libdix.a(resource.o):(.note.stapsdt+0x24): undefined reference to `Xserver_resource__alloc_semaphore'
  ../../dix/.libs/libdix.a(resource.o):(.note.stapsdt+0x88): undefined reference to `Xserver_resource__free_semaphore'
  ../../dix/.libs/libdix.a(resource.o):(.note.stapsdt+0xe8): undefined reference to `Xserver_resource__free_semaphore'
  ../../dix/.libs/libdix.a(resource.o):(.note.stapsdt+0x14c): undefined reference to `Xserver_resource__free_semaphore'
  ../../dix/.libs/libdix.a(resource.o):(.note.stapsdt+0x1b0): undefined reference to `Xserver_resource__free_semaphore'
  ../../os/.libs/libos.a(connection.o): In function `ClientAuthorized':
  /home/m/xorg/xserver/os/connection.c:671: undefined reference to `Xserver_client__auth_semaphore'
  /home/m/xorg/xserver/os/connection.c:651: undefined reference to `Xserver_client__auth_semaphore'
  ../../os/.libs/libos.a(connection.o):(.note.stapsdt+0x24): undefined reference to `Xserver_client__auth_semaphore'
  ../../os/.libs/libos.a(connection.o):(.note.stapsdt+0x84): undefined reference to `Xserver_client__connect_semaphore'
  collect2: error: ld returned 1 exit status
  Makefile:693: recipe for target 'Xvfb' failed
  make[3]: *** [Xvfb] Error 1
  make[3]: Leaving directory '/home/m/xorg/xserver/hw/vfb'
  Makefile:754: recipe for target 'all-recursive' failed
  make[2]: *** [all-recursive] Error 1
  make[2]: Leaving directory '/home/m/xorg/xserver/hw/vfb'
  Makefile:613: recipe for target 'all-recursive' failed
  make[1]: *** [all-recursive] Error 1
  make[1]: Leaving directory '/home/m/xorg/xserver/hw'
  Makefile:782: recipe for target 'all-recursive' failed
  make: *** [all-recursive] Error 1

So put it into XSERVER_LIBS after the DIX_LIB and OS_LIB.


More information about the xorg-devel mailing list