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: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-04-19 20:30 UTC by John E. Hein
Modified: 2021-10-25 00:39 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"
Comment 3 commit-hook freebsd_committer freebsd_triage 2021-10-18 21:23:56 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=e1d6d6f9249d37c10a0df68024c7dacebdc7bf98

commit e1d6d6f9249d37c10a0df68024c7dacebdc7bf98
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2021-10-18 21:19:53 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2021-10-18 21:21:17 +0000

    lorder: process read-only data symbols

    Previously they were skipped.  lorder(1) serves no functional purpose
    today but we might as well address this longstanding bug while it is
    still in the tree.

    PR:             133860
    MFC after:      1 week
    Submitted by:   John Hein

 usr.bin/lorder/lorder.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Comment 4 commit-hook freebsd_committer freebsd_triage 2021-10-25 00:38:05 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=7a789031139eef4626f7d751a2d24a58d1693c98

commit 7a789031139eef4626f7d751a2d24a58d1693c98
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2021-10-18 21:19:53 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2021-10-25 00:37:05 +0000

    lorder: process read-only data symbols

    Previously they were skipped.  lorder(1) serves no functional purpose
    today but we might as well address this longstanding bug while it is
    still in the tree.

    PR:             133860
    MFC after:      1 week
    Submitted by:   John Hein

    (cherry picked from commit e1d6d6f9249d37c10a0df68024c7dacebdc7bf98)

 usr.bin/lorder/lorder.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Comment 5 commit-hook freebsd_committer freebsd_triage 2021-10-25 00:39:13 UTC
A commit in branch stable/12 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=28a6e1beea0e179a5a52b338b8ea44a0766fd968

commit 28a6e1beea0e179a5a52b338b8ea44a0766fd968
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2021-10-18 21:19:53 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2021-10-25 00:37:56 +0000

    lorder: process read-only data symbols

    Previously they were skipped.  lorder(1) serves no functional purpose
    today but we might as well address this longstanding bug while it is
    still in the tree.

    PR:             133860
    MFC after:      1 week
    Submitted by:   John Hein

    (cherry picked from commit e1d6d6f9249d37c10a0df68024c7dacebdc7bf98)

 usr.bin/lorder/lorder.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)