Bug 26822 - How to prevent a STT_FILE with absolute path in the linked image
Summary: How to prevent a STT_FILE with absolute path in the linked image
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.36
: P2 normal
Target Milestone: 2.36
Assignee: Alan Modra
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-10-30 20:41 UTC by Fangrui Song
Modified: 2021-01-04 10:29 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed: 2021-01-04 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fangrui Song 2020-10-30 20:41:30 UTC
ld.bfd copies non-STT_SECTION local symbols from input object files.
If an object file does not have STT_FILE symbols (no .file directive) but has
non-STT_SECTION local symbols, ld.bfd synthesizes a STT_FILE symbol.

         bfd/elflink.c
         /* In the absence of debug info, bfd_find_nearest_line uses
             FILE symbols to determine the source file for local
             function symbols.  Provide a FILE symbol here if input
             files lack such, so that their symbols won't be
             associated with a previous input file.  It's not the
             source file, but the best we can do.  */

The ELF spec says:

> STT_FILE - Conventionally, the symbol's name gives the name of the source file associated with the object file. A file symbol has STB_LOCAL binding, its section index is SHN_ABS, and it precedes the other STB_LOCAL symbols for the file, if it is present.

Without the synthesized STT_FILE, consumers may attribute the copied STB_LOCAL symbols to the previous file (with STT_FILE).

On ARM, mapping symbols (e.g. $a) can be everywhere.
For crti.o and crtn.o, compiler drivers pass the absolute paths to ld, so the synthesized STT_FILE has an absolute path.

However, if the user wants to pursue "Local determinism: Like incremental basic determinism, but builds are also independent of the name of the build directory" (https://blog.llvm.org/2019/11/deterministic-builds-with-clang-and-lld.html), the absolute path can actually get in the way.
The usual -fdebug-prefix-map (-ffile-prefix-map) is not effective to the ld synthesized paths.
Comment 1 Alan Modra 2021-01-04 06:45:08 UTC
I guess the file base name would do here.
Comment 2 cvs-commit@gcc.gnu.org 2021-01-04 10:27:37 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=5b4293ba3c207ebdaea3631819b9459f0a10e761

commit 5b4293ba3c207ebdaea3631819b9459f0a10e761
Author: Alan Modra <amodra@gmail.com>
Date:   Mon Jan 4 17:13:51 2021 +1030

    PR26822, How to prevent a STT_FILE with absolute path in the linked image
    
    bfd/
            PR 26822
            * elflink.c (elf_link_input_bfd): Use the file base name in
            linker generated STT_FILE symbols.
    ld/
            PR 26822
            * testsuite/ld-arm/non-contiguous-arm2.d: Adjust STT_FILE symbol match.
            * testsuite/ld-arm/non-contiguous-arm3.d: Likewise.
            * testsuite/ld-arm/non-contiguous-arm5.d: Likewise.
            * testsuite/ld-arm/non-contiguous-arm6.d: Likewise.
            * testsuite/ld-i386/tlsbin.rd: Likewise.
            * testsuite/ld-i386/tlsbin2.rd: Likewise.
            * testsuite/ld-i386/tlsbindesc.rd: Likewise.
            * testsuite/ld-i386/tlsdesc.rd: Likewise.
            * testsuite/ld-i386/tlsnopic.rd: Likewise.
            * testsuite/ld-i386/tlspic.rd: Likewise.
            * testsuite/ld-i386/tlspic2.rd: Likewise.
            * testsuite/ld-mips-elf/global-local-symtab-sort-n64.d: Likewise.
            * testsuite/ld-mips-elf/global-local-symtab-sort-n64t.d: Likewise.
            * testsuite/ld-mips-elf/global-local-symtab-sort-o32.d: Likewise.
            * testsuite/ld-mips-elf/global-local-symtab-sort-o32t.d: Likewise.
            * testsuite/ld-plugin/pr17973.d: Likewise.
            * testsuite/ld-tic6x/shlib-1.rd: Likewise.
            * testsuite/ld-tic6x/shlib-1b.rd: Likewise.
            * testsuite/ld-tic6x/shlib-1r.rd: Likewise.
            * testsuite/ld-tic6x/shlib-1rb.rd: Likewise.
            * testsuite/ld-tic6x/shlib-app-1.rd: Likewise.
            * testsuite/ld-tic6x/shlib-app-1b.rd: Likewise.
            * testsuite/ld-tic6x/shlib-app-1r.rd: Likewise.
            * testsuite/ld-tic6x/shlib-app-1rb.rd: Likewise.
            * testsuite/ld-tic6x/shlib-noindex.rd: Likewise.
            * testsuite/ld-tic6x/static-app-1.rd: Likewise.
            * testsuite/ld-tic6x/static-app-1b.rd: Likewise.
            * testsuite/ld-tic6x/static-app-1r.rd: Likewise.
            * testsuite/ld-tic6x/static-app-1rb.rd: Likewise.
            * testsuite/ld-x86-64/tlsbin.rd: Likewise.
            * testsuite/ld-x86-64/tlsbin2.rd: Likewise.
            * testsuite/ld-x86-64/tlsbindesc.rd: Likewise.
            * testsuite/ld-x86-64/tlsdesc.rd: Likewise.
            * testsuite/ld-x86-64/tlspic.rd: Likewise.
            * testsuite/ld-x86-64/tlspic2.rd: Likewise.
            * testsuite/ld-xtensa/tlsbin.rd: Likewise.
            * testsuite/ld-xtensa/tlspic.rd: Likewise.
Comment 3 Alan Modra 2021-01-04 10:29:10 UTC
Fixed for 2.36