Page MenuHomeFreeBSD

(PR 194296) bfd: Improve common ELF linking error message
ClosedPublic

Authored by dim on Nov 12 2014, 7:08 PM.

Details

Summary

If the BFD object looks like a typical shared library, suggest adding
'-l<foo>', where <foo> has the 'lib' prefix and '.so<bar>' or '.a'
suffix removed.

Otherwise, suggest adding '-l:<foo>', where <foo> is the full DT_SONAME.

Sponsored by: EMC / Isilon storage division

Test Plan

a.c:

extern void elf32_fsize(void);
int
main(int argc, char **argv)
{
  elf32_fsize();
  return 0;
}

$ cc a.c -ldwarf
/usr/bin/ld: //usr/lib/libelf.so.2: invalid DSO for symbol `elf32_fsize@@R1.0' definition
//usr/lib/libelf.so.2: could not read symbols: Bad value
cc: error: linker command failed with exit code 1 (use -v to see invocation)

Diff Detail

Repository
rS FreeBSD src repository
Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

cse_cem_gmail_com retitled this revision from to bfd: Improve common ELF linking error message.
cse_cem_gmail_com updated this object.
cse_cem_gmail_com edited the test plan for this revision. (Show Details)
cse_cem_gmail_com updated this object.
cse_cem_gmail_com edited the test plan for this revision. (Show Details)
cse_cem_gmail_com edited the test plan for this revision. (Show Details)
cse_cem_gmail_com edited the test plan for this revision. (Show Details)
cse_cem_gmail_com added a reviewer: emaste.
cse_cem_gmail_com retitled this revision from bfd: Improve common ELF linking error message to (PR 194296) bfd: Improve common ELF linking error message.Nov 12 2014, 7:13 PM
contrib/binutils/bfd/elflink.c
4366–4396 ↗(On Diff #2378)

This seemed confusing to me so I tried reworking it and came up with the change below. Let me know if you think it's an improvement.

size_t lend = 0;

if (strncmp(soname, "lib", 3) == 0)
{
        len = strlen(soname);
        if (len > 5 && strcmp(soname + len - 2, ".a") == 0) {
                lend = len - 5;
        } else {
                while (len > 6 && (isdigit(soname[len-1]) || soname[len-1] == '.'))
                        len--;
                if (strncmp(soname + len - 3, ".so", 3) == 0)
                        lend = len - 6;
        }
        if (lend != 0) {
                strlcpy(libname, soname + 3, lend + 1);
                print_name = libname;
                looks_soish = TRUE;

        }
}
contrib/binutils/bfd/elflink.c
4366–4396 ↗(On Diff #2378)

Sure, looks fine to me. (Modulo bfd ISDIGIT() instead of isdigit(3).)

emaste edited reviewers, added: cse_cem_gmail_com; removed: emaste.

Rewrite in a way that's more clear to me

cse_cem_gmail_com edited edge metadata.

Looks good to me.

(Phabricator seems to clobber the GNU-style mixed tabs/spaces indent, but I assume you did it right.)

This revision is now accepted and ready to land.Nov 12 2014, 8:28 PM
dim added a reviewer: emaste.
dim edited edge metadata.

Changed to no longer use a buffer of fixed size on the stack. Instead, record the length to print, and use printf's * modifier to adjust the field width.

This revision now requires review to proceed.Dec 1 2014, 10:41 PM

If you've tested it and it works, looks good to me. I just want this to be fixed, and every iteration seems like a basically adequate way of solving the problem to me.

contrib/binutils/bfd/elflink.c
4361 ↗(On Diff #2593)

As long as we're bikeshedding, strlen(3) returns size_t. Cast to int in the format string call.

cse_cem_gmail_com edited edge metadata.

Er, mark reviewed. Phabricator is hard.

This revision is now accepted and ready to land.Dec 1 2014, 11:03 PM
emaste edited edge metadata.
dim edited edge metadata.

Minor update, use 'lend' directly for 'print_len', instead of adding 1. Otherwise, a dot character would be displayed in the -l suggestion.

This revision now requires review to proceed.Dec 2 2014, 12:48 AM
This revision is now accepted and ready to land.Dec 2 2014, 12:59 AM
emaste edited edge metadata.

LGTM with an update to the .pot file

dim updated this revision to Diff 2595.

Closed by commit rS275386 (authored by @dim).