Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

readelf complains that .note.rustc is malformed #27372

Closed
saschmit opened this issue Jul 29, 2015 · 4 comments · Fixed by #35409
Closed

readelf complains that .note.rustc is malformed #27372

saschmit opened this issue Jul 29, 2015 · 4 comments · Fixed by #35409
Labels
O-linux Operating system: Linux

Comments

@saschmit
Copy link

After building rustc 1.1.0, if I run readelf --section-headers --note over the shared libraries produced, I see output like the following:

$ readelf --section-headers --note x86_64-unknown-linux-gnu/stage2/lib/libarena-e9599659.so
There are 30 section headers, starting at offset 0xef98:

Section Headers:
  [Nr] Name              Type             Address           Offset
       Size              EntSize          Flags  Link  Info  Align
  [ 0]                   NULL             0000000000000000  00000000
       0000000000000000  0000000000000000           0     0     0
  [ 1] .note.gnu.build-i NOTE             0000000000000200  00000200
       0000000000000024  0000000000000000   A       0     0     4
  [ 2] .gnu.hash         GNU_HASH         0000000000000228  00000228
       0000000000000118  0000000000000000   A       3     0     8
  [ 3] .dynsym           DYNSYM           0000000000000340  00000340
       00000000000003d8  0000000000000018   A       4     2     8
  [ 4] .dynstr           STRTAB           0000000000000718  00000718
       0000000000000687  0000000000000000   A       0     0     1
  [ 5] .gnu.version      VERSYM           0000000000000da0  00000da0
       0000000000000052  0000000000000002   A       3     0     2
  [ 6] .gnu.version_r    VERNEED          0000000000000df8  00000df8
       0000000000000040  0000000000000000   A       4     2     8
  [ 7] .rela.dyn         RELA             0000000000000e38  00000e38
       0000000000000150  0000000000000018   A       3     0     8
  [ 8] .rela.plt         RELA             0000000000000f88  00000f88
       0000000000000150  0000000000000018  AI       3    10     8
  [ 9] .init             PROGBITS         00000000000010d8  000010d8
       000000000000001a  0000000000000000  AX       0     0     4
  [10] .plt              PROGBITS         0000000000001100  00001100
       00000000000000f0  0000000000000010  AX       0     0     16
  [11] .text             PROGBITS         00000000000011f0  000011f0
       00000000000010ac  0000000000000000  AX       0     0     16
  [12] .fini             PROGBITS         000000000000229c  0000229c
       0000000000000009  0000000000000000  AX       0     0     4
  [13] .eh_frame_hdr     PROGBITS         00000000000022a8  000022a8
       00000000000000b4  0000000000000000   A       0     0     4
  [14] .eh_frame         PROGBITS         0000000000002360  00002360
       000000000000033c  0000000000000000   A       0     0     8
  [15] .gcc_except_table PROGBITS         000000000000269c  0000269c
       000000000000028c  0000000000000000   A       0     0     4
  [16] .init_array       INIT_ARRAY       0000000000202db0  00002db0
       0000000000000008  0000000000000000  WA       0     0     8
  [17] .fini_array       FINI_ARRAY       0000000000202db8  00002db8
       0000000000000008  0000000000000000  WA       0     0     8
  [18] .jcr              PROGBITS         0000000000202dc0  00002dc0
       0000000000000008  0000000000000000  WA       0     0     8
  [19] .data.rel.ro      PROGBITS         0000000000202dc8  00002dc8
       0000000000000008  0000000000000000  WA       0     0     8
  [20] .dynamic          DYNAMIC          0000000000202dd0  00002dd0
       00000000000001e0  0000000000000010  WA       4     0     8
  [21] .got              PROGBITS         0000000000202fb0  00002fb0
       0000000000000050  0000000000000008  WA       0     0     8
  [22] .got.plt          PROGBITS         0000000000203000  00003000
       0000000000000088  0000000000000008  WA       0     0     8
  [23] .data             PROGBITS         0000000000203088  00003088
       0000000000000008  0000000000000000  WA       0     0     8
  [24] .note.rustc       NOTE             0000000000203090  00003090
       000000000000ab12  0000000000000000  WA       0     0     16
  [25] .bss              NOBITS           000000000020dba4  0000dba2
       0000000000000004  0000000000000000  WA       0     0     4
  [26] .comment          PROGBITS         0000000000000000  0000dba2
       000000000000002c  0000000000000001  MS       0     0     1
  [27] .shstrtab         STRTAB           0000000000000000  0000dbce
       0000000000000115  0000000000000000           0     0     1
  [28] .symtab           SYMTAB           0000000000000000  0000dce8
       0000000000000978  0000000000000018          29    62     8
  [29] .strtab           STRTAB           0000000000000000  0000e660
       0000000000000938  0000000000000000           0     0     1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), l (large)
  I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)

Displaying notes found at file offset 0x00000200 with length 0x00000024:
  Owner                 Data size   Description
  GNU                  0x00000014   NT_GNU_BUILD_ID (unique build ID bitstring)
    Build ID: 16a45cac5814e1be056835720bcbd14710fab8eb

Displaying notes found at file offset 0x00003090 with length 0x0000ab12:
  Owner                 Data size   Description
readelf: Warning: note with invalid namesz and/or descsz found at offset 0x0
readelf: Warning:  type: 0x6007bded, namesize: 0x74737572, descsize: 0x02000000

Based on the section list, it appears that the malformed section is .note.rustc

Built using the x86_64 bootstrap rustc:

$ ./x86_64-unknown-linux-gnu/stage0/bin/rustc --version --verbose
rustc 1.1.0-dev (857ef6e27 2015-04-27) (built 2015-04-27)
binary: rustc
commit-hash: 857ef6e272e5634cb9f3e6ee50eb6bc2a2e71651
commit-date: 2015-04-27
build-date: 2015-04-27
host: x86_64-unknown-linux-gnu
release: 1.1.0-dev
@Aatch
Copy link
Contributor

Aatch commented Jul 29, 2015

That section contains the metadata for the library, there does appear to be some sort of defined structure for the section, so maybe we could try and fit into that a bit better? We'd need to figure out how to prevent tools like readelf from trying to print it all out though when using these tools.

@saschmit
Copy link
Author

This looks related to #26764 -- readelf doesn't complain about the libraries generated after applying the referenced patch (tylerwhall/rust@fc91059).

@steveklabnik steveklabnik added O-linux Operating system: Linux and removed O-linux Operating system: Linux labels Jul 29, 2015
@eddyb
Copy link
Member

eddyb commented May 19, 2016

Turns out that this can actually crash the GNU dynamic linker - me and @solson both observed this with a patch that increases the size of metadata (by serializing MIR for everything).

Changing the section name to .rustc works but it behaves like .data, while it would be best if the section was never loaded at runtime.
cc @alexcrichton

@eddyb
Copy link
Member

eddyb commented May 19, 2016

Oh, turns out that's #26764.

bors added a commit that referenced this issue Aug 14, 2016
[MIR] Add Storage{Live,Dead} statements to emit llvm.lifetime.{start,end}.

Storage live ranges are tracked for all MIR variables and temporaries with a drop scope.
`StorageLive` is lowered to `llvm.lifetime.start` and `StorageDead` to `llvm.lifetime.end`.

There are some improvements possible here, such as:
* pack multiple storage liveness statements by using the index of first local + `u64` bitset
* enforce that locals are not directly accessed outside their storage live range
* shrink storage live ranges for never-borrowed locals to initialization -> last use
* emit storage liveness statements for *all* temporaries
 * however, the remaining ones are *always* SSA immediates, so they'd be noop in MIR trans
 * could have a flag on the temporary that its storage is irrelevant (a la C's old `register`)
   * would also deny borrows if necessary
    * this seems like an overcompliation and with packing & optimizations it may be pointless

Even in the current state, it helps stage2 `rustc` compile `boiler` without overflowing (see #35408).

A later addition fixes #26764 and closes #27372 by emitting `.section` directives for dylib metadata to avoid them being allocated into memory or read as `.note`. For this PR, those bugs were tripping valgrind.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-linux Operating system: Linux
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants