[all-commits] [llvm/llvm-project] e07dfa: [MC][ELF] Improve st_size propagation rule

Fangrui Song via All-commits all-commits at lists.llvm.org
Fri Apr 8 10:06:57 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: e07dfa5328b0ca1465ae7b749e1ac2d994741e27
      https://github.com/llvm/llvm-project/commit/e07dfa5328b0ca1465ae7b749e1ac2d994741e27
  Author: Fangrui Song <i at maskray.me>
  Date:   2022-04-08 (Fri, 08 Apr 2022)

  Changed paths:
    M llvm/lib/MC/ELFObjectWriter.cpp
    M llvm/test/MC/ELF/offset.s

  Log Message:
  -----------
  [MC][ELF] Improve st_size propagation rule

`.symver foo, foo at ver` creates the MCSymbolELF `foo at ver` whose almost all
attributes (including st_size) should inherit from `foo` (GNU as behavior).

a041ef1bd8905f0d58e301c6830b183002ff1847 added st_size propagation which works
for many cases but fails for the following one:

```
.set __GLIBC_2_12_sys_errlist, _sys_errlist_internal
.type   __GLIBC_2_12_sys_errlist, at object
.size   __GLIBC_2_12_sys_errlist, 1080
.symver __GLIBC_2_12_sys_errlist, sys_errlist at GLIBC_2.12
...
_sys_errlist_internal:
.size   _sys_errlist_internal, 1072
```

`sys_errlist at GLIBC_2.12`'s st_size is 1072 (incorrect), which does not match
`__GLIBC_2_12_sys_errlist`'s st_size: 1080.

The problem is that `Base` is (the final) `_sys_errlist_internal` while we want
to respect (the intermediate) `__GLIBC_2_12_sys_errlist`'s st_size.
Fix this by following the MCSymbolRefExpr assignment chain and finding
the closest non-null `getSize()`, which covers most needs. Notably MCBinaryExpr
is not handled, but it is rare enough to matter.

Reviewed By: peter.smith

Differential Revision: https://reviews.llvm.org/D123283




More information about the All-commits mailing list