[llvm-bugs] [Bug 42140] New: Fix stream interleaving caused by llvm-readelf stream usage
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Jun 5 08:11:07 PDT 2019
https://bugs.llvm.org/show_bug.cgi?id=42140
Bug ID: 42140
Summary: Fix stream interleaving caused by llvm-readelf stream
usage
Product: tools
Version: trunk
Hardware: PC
OS: Windows NT
Status: NEW
Severity: normal
Priority: P
Component: llvm-readobj
Assignee: unassignedbugs at nondot.org
Reporter: jh7370.2008 at my.bristol.ac.uk
CC: jh7370.2008 at my.bristol.ac.uk, llvm-bugs at lists.llvm.org
Consider the following test:
# RUN: yaml2obj %s -o %t
# RUN: llvm-readelf --dynamic-table --symbols %t | FileCheck %s
# CHECK: foo{{$}}
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .dynamic
Type: SHT_DYNAMIC
Entries:
- Tag: DT_NULL
Value: 0
Symbols:
- Name: foo
ProgramHeaders:
- Type: PT_DYNAMIC
Sections:
- Section: .dynamic
The output should print a symbol table, followed by a new line and then the
dynamic table like this:
Symbol table '.symtab' contains 2 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
1: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND foo
DynamicSection [ (1 entries)
Tag Type Name/Value
0x0000000000000000 NULL 0x0
]
This is what happens when I run the llvm-readelf command directly on the
command-line. However, when the output is redirected to a file or other process
(such as when run through lit), the output is as follows:
Symbol table '.symtab' contains 2 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
1: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND fooDynamicSection [
(1 entries)
Tag Type Name/Value
0x0000000000000000 NULL 0x0
]
Note that there is an extra new line at the end of the output, in addition to
no new line between the "foo" symbol name and "DynamicSection". As such the
above test will fail.
I did some investigation and the problem is that the GNUStyle dumper has its
own stream instance, which is buffered.
class GNUStyle {
formatted_raw_ostream OS;
...
};
This stream wraps the ScopedPrinter's stream that ELFDumper is provided, and
adds the layer of buffering over the top. This is fine as long as all printing
is done exclusively through the GNUStyle's variable, or exclusively through
ELFDumper's stream variable. If the two are mixed, the following happens:
GNUStyle->OS prints some stuff, buffers the remainder
ELFDumper->OS prints some stuff
GNUStyle->OS prints the remainder of its buffer
This is bad, as it results in interleaving. The exact amount depends on what is
printed, because the GNUStyle buffer is sometimes flushed, but not always.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190605/a55fbc89/attachment.html>
More information about the llvm-bugs
mailing list