Page MenuHomeFreeBSD

vdso linker scripts: explicitly specify output arch and target
ClosedPublic

Authored by kib on Feb 3 2022, 2:41 PM.
Tags
None
Referenced Files
Unknown Object (File)
Apr 6 2024, 12:45 PM
Unknown Object (File)
Feb 22 2024, 6:00 AM
Unknown Object (File)
Dec 22 2023, 9:59 AM
Unknown Object (File)
Dec 20 2023, 2:16 AM
Unknown Object (File)
Nov 20 2023, 11:51 AM
Unknown Object (File)
Sep 12 2023, 5:29 AM
Unknown Object (File)
Aug 7 2023, 1:25 AM
Unknown Object (File)
Aug 7 2023, 1:25 AM
Subscribers

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

LGTM for lld, which ignores OUTPUT_ARCH and does not do much with TARGET

void ScriptParser::readOutputArch() {
  // OUTPUT_ARCH is ignored for now.
  expect("(");
  while (!errorCount() && !consume(")"))
    skip();
}
void ScriptParser::readTarget() {
  // TARGET(foo) is an alias for "--format foo". Unlike GNU linkers,
  // we accept only a limited set of BFD names (i.e. "elf" or "binary")
  // for --format. We recognize only /^elf/ and "binary" in the linker
  // script as well.
  expect("(");
  StringRef tok = next();
  expect(")");

  if (tok.startswith("elf"))
    config->formatBinary = false;
  else if (tok == "binary")
    config->formatBinary = true;
  else
    setError("unknown target: " + tok);
}

from ld docs:

  • OUTPUT_ARCH ( bfdname ) Specify a particular output machine architecture, with one of the names used by the BFD back-end routines (see section BFD). This command is often unnecessary; the architecture is most often set implicitly by either the system BFD configuration or as a side effect of the OUTPUT_FORMAT command.
  • OUTPUT_FORMAT ( bfdname ) When ld is configured to support multiple object code formats, you can use this command to specify a particular output format. bfdname is one of the names used by the BFD back-end routines (see section BFD). The effect is identical to the effect of the `--oformat' command-line option. This selection affects only the output file; the related command TARGET affects primarily input files.

Even more weird. I remember I had to add OUTPUT_ARCH() for ia32 vdso. Might be it was due to ld.bfd. But John reports that it cannot be built with ld.bfd anyway.

Only tried with the TARGET line added to vdso_amd64_ia32.ldscript and that did work.

This revision is now accepted and ready to land.Feb 7 2022, 9:48 PM

IMO it's worth noting in the commit (or maybe even a comment in the file) that these are for ld.bfd and lld doesn't do much with them, the only thing it does is produce ELF or binary based on TARGET

In D34157#773704, @jhb wrote:

Only tried with the TARGET line added to vdso_amd64_ia32.ldscript and that did work.

Do you mean, you want me to remove OUTPUT_ARCH() from both scripts?

This revision now requires review to proceed.Feb 7 2022, 10:43 PM
This revision is now accepted and ready to land.Feb 8 2022, 12:03 AM
In D34157#773726, @kib wrote:
In D34157#773704, @jhb wrote:

Only tried with the TARGET line added to vdso_amd64_ia32.ldscript and that did work.

Do you mean, you want me to remove OUTPUT_ARCH() from both scripts?

No, I didn't try with the OUTPUT_ARCH removed from the i386 script (I meant I only tried that part of your patch and didn't change vdso_amd64.ldscript). I think you can either merge as-is or only add the change to vdso_amd64_ia32.ldscript and leave vdso_amd64.ldscript alone.