Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 19 Apr 2009 13:27:07 -0600 (MDT)
From:      John Hein <jhein@timing.com>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   bin/133860: lorder misses symbols defined in read only data section.
Message-ID:  <200904191927.n3JJR7aO018133@gromit.timing.com>
Resent-Message-ID: <200904191930.n3JJU2eR031826@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         133860
>Category:       bin
>Synopsis:       lorder misses symbols defined in read only data section.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Apr 19 19:30:01 UTC 2009
>Closed-Date:
>Last-Modified:
>Originator:     John Hein
>Release:        FreeBSD 8.x 20090418 and earlier
>Organization:
>Environment:

>Description:

If a symbol is defined in the read only data section (shows up as an 'R'
in nm output), lorder(1) doesn't see it as a defined symbol.  As a result,
lorder can miss dependencies.

>How-To-Repeat:

Here is a contrived example that tries to use a read only symbol
defined in libz...

% cat ltest.c
#include <stdio.h>
extern int _dist_code;
int
main()
{
    printf("_dist_code: %d\n", _dist_code);
    return 0;
}
% nm -o ltest.o
ltest.o:         U _dist_code
ltest.o:00000000 T main
ltest.o:         U printf
% nm -go /usr/lib/libz.a | grep dist_code
/usr/lib/libz.a:deflate.o:         U _dist_code
/usr/lib/libz.a:trees.o:00000000 R _dist_code
% lorder ltest.o /usr/lib/libz.a /usr/lib/libc.a
ltest.o ltest.o
/usr/lib/libz.a /usr/lib/libz.a
/usr/lib/libc.a /usr/lib/libc.a
/usr/lib/libz.a /usr/lib/libc.a
/usr/lib/libz.a /usr/lib/libc.a
/usr/lib/libz.a /usr/lib/libc.a
/usr/lib/libz.a /usr/lib/libc.a
/usr/lib/libz.a /usr/lib/libc.a
/usr/lib/libz.a /usr/lib/libc.a
/usr/lib/libz.a /usr/lib/libc.a
/usr/lib/libz.a /usr/lib/libc.a
/usr/lib/libz.a /usr/lib/libc.a
/usr/lib/libz.a /usr/lib/libc.a
/usr/lib/libz.a /usr/lib/libc.a
/usr/lib/libz.a /usr/lib/libc.a
/usr/lib/libz.a /usr/lib/libc.a
/usr/lib/libz.a /usr/lib/libc.a
/usr/lib/libz.a /usr/lib/libc.a
/usr/lib/libz.a /usr/lib/libc.a
/usr/lib/libz.a /usr/lib/libc.a
/usr/lib/libz.a /usr/lib/libc.a
ltest.o /usr/lib/libc.a
/usr/lib/libz.a /usr/lib/libc.a
/usr/lib/libz.a /usr/lib/libc.a
/usr/lib/libz.a /usr/lib/libc.a
/usr/lib/libz.a /usr/lib/libc.a
/usr/lib/libz.a /usr/lib/libc.a
/usr/lib/libz.a /usr/lib/libc.a

Notice the missing dependency of ltest.o on libz.a.

So if you use lorder | tsort to determine link order, it can fail...

% gcc --nostdlib /usr/lib/libc.a `lorder ltest.o /usr/lib/libz.a |tsort -q` -o ltest
ltest.o(.text+0x12): In function `main':
: undefined reference to `_dist_code'



>Fix:

Index: lorder.sh
===================================================================
RCS file: /base/FreeBSD-CVS/src/usr.bin/lorder/lorder.sh,v
retrieving revision 1.7
diff -u -p -r1.7 lorder.sh
--- lorder.sh	15 Jul 2005 15:21:12 -0000	1.7
+++ lorder.sh	19 Apr 2009 18:43:01 -0000
@@ -65,8 +65,8 @@ done
 # if the line has " U " it's a globally undefined symbol, put it into
 # the reference file.
 ${NM} -go $* | sed "
-	/ [TDW] / {
-		s/:.* [TDW] / /
+	/ [RTDW] / {
+		s/:.* [RTDW] / /
 		w $S
 		d
 	}
>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200904191927.n3JJR7aO018133>