Bug 133860 - [patch] lorder(1) misses symbols defined in read only data section.
Summary: [patch] lorder(1) misses symbols defined in read only data section.
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-04-19 20:30 UTC by John E. Hein
Modified: 2018-05-20 23:57 UTC (History)
2 users (show)

See Also:


Attachments
file.diff (504 bytes, patch)
2009-04-19 20:30 UTC, John E. Hein
no flags Details | Diff
Look for 'R' symbols, too. (553 bytes, patch)
2014-09-15 15:58 UTC, John Hein
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description John E. Hein 2009-04-19 20:30:01 UTC
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'
Comment 1 John Hein 2014-09-15 15:58:51 UTC
Created attachment 147350 [details]
Look for 'R' symbols, too.

Dust off an old bug - still an issue.

Add 'R' symbols to search list.
Comment 2 Eitan Adler freebsd_committer freebsd_triage 2018-05-20 23:57:20 UTC
For bugs matching the following conditions:
- Status == In Progress
- Assignee == "bugs@FreeBSD.org"
- Last Modified Year <= 2017

Do
- Set Status to "Open"