Skip to content

Commit 654b51c

Browse files
authored
Fix elf_parser.h and tests for ze_debug_info (#144)
* Fix `elf_parser.h` as a follow up to 99d428a * Fix two more issues in static code analysis. * Fix tests for `ze_debug_info` and add warning for out-dated sample. Signed-off-by: Schilling, Matthew <[email protected]>
1 parent 984b623 commit 654b51c

9 files changed

+28
-11
lines changed

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.49.26
1+
0.49.27

samples/cl_debug_info/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,4 @@ Also one may need to add an actual path to IGA *.dll into PATH before sample run
131131
```
132132
set PATH=%PATH%;<iga_dll_path>
133133
cl_debug_info.exe ..\..\cl_gemm\build\cl_gemm.exe
134-
```
134+
```

samples/cl_debug_info/cl_debug_info_collector.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -531,4 +531,4 @@ class ClDebugInfoCollector {
531531
KernelDebugInfoMap kernel_debug_info_map_;
532532
};
533533

534-
#endif // PTI_SAMPLES_CL_DEBUG_INFO_CL_DEBUG_INFO_COLLECTOR_H_
534+
#endif // PTI_SAMPLES_CL_DEBUG_INFO_CL_DEBUG_INFO_COLLECTOR_H_

samples/ze_debug_info/README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ As a result, listing like the following will be printed for each kernel (once pe
9898
- [Intel(R) Graphics Compute Runtime for oneAPI Level Zero and OpenCL(TM) Driver](https://github.com/intel/compute-runtime)
9999

100100
## Build and Run
101+
102+
**Note**: This sample does not support IGC's latest binary format (ZEBinary).
103+
To use this sample, run `export IGC_EnableZEBinary=0` before running the sample.
104+
101105
### Linux
102106
Run the following commands to build the sample:
103107
```sh
@@ -138,4 +142,4 @@ Also one may need to add an actual path to IGA *.dll into PATH before sample run
138142
```
139143
set PATH=%PATH%;<iga_dll_path>
140144
ze_debug_info.exe ..\..\ze_gemm\build\ze_gemm.exe
141-
```
145+
```

samples/ze_debug_info/ze_debug_info_collector.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ using KernelDebugInfoMap = std::map<std::string, KernelDebugInfo>;
4343
class ZeDebugInfoCollector {
4444
public: // User Interface
4545
static ZeDebugInfoCollector* Create() {
46+
std::cout << "[INFO] At the moment, this sample is incompatible with" <<
47+
" IGC's ZE binary format." << std::endl;
48+
std::cout << "Run `export IGC_EnableZEBinary=0` to use old format." << std::endl;
49+
4650
ZeDebugInfoCollector* collector = new ZeDebugInfoCollector();
4751
PTI_ASSERT(collector != nullptr);
4852

@@ -357,4 +361,4 @@ class ZeDebugInfoCollector {
357361
KernelDebugInfoMap kernel_debug_info_map_;
358362
};
359363

360-
#endif // PTI_SAMPLES_ZE_DEBUG_INFO_ZE_DEBUG_INFO_COLLECTOR_H_
364+
#endif // PTI_SAMPLES_ZE_DEBUG_INFO_ZE_DEBUG_INFO_COLLECTOR_H_

tests/samples/ze_debug_info.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def run(path, option):
4343
return None
4444

4545
def main(option):
46+
os.environ["IGC_EnableZEBinary"] = "0"
4647
path = utils.get_sample_build_path("ze_debug_info")
4748
if option == "dpc":
4849
log = dpc_gemm.main("gpu")
@@ -68,4 +69,4 @@ def main(option):
6869
option = "dpc"
6970
log = main(option)
7071
if log:
71-
print(log)
72+
print(log)

utils/debug_line_parser.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <string.h>
1111

12+
#include <cstdint>
1213
#include <string>
1314
#include <vector>
1415

@@ -87,6 +88,8 @@ class DebugLineParser {
8788

8889
ptr += sizeof(Dwarf32LineNumberProgramHeader);
8990

91+
// Each decode parses sizeof(uint32_t) bytes and moves ptr
92+
PTI_ASSERT(sizeof(uint32_t)*header->opcode_base < size_ + sizeof(uint32_t));
9093
// standard_opcode_lengths
9194
for (uint8_t i = 1; i < header->opcode_base; ++i) {
9295
uint32_t value = 0;
@@ -137,4 +140,4 @@ class DebugLineParser {
137140
uint32_t size_;
138141
};
139142

140-
#endif // PTI_UTILS_DEBUG_LINE_PARSER_H_
143+
#endif // PTI_UTILS_DEBUG_LINE_PARSER_H_

utils/elf_parser.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <string.h>
1111

12+
#include <limits>
1213
#include <vector>
1314

1415
#include "elf.h"
@@ -21,7 +22,7 @@ class ElfParser {
2122
ElfParser(const uint8_t* data, uint32_t size) : data_(data), size_(size) {}
2223

2324
bool IsValid() const {
24-
if (data_ == nullptr || size_ != sizeof(Elf64Header)) {
25+
if (data_ == nullptr || size_ < sizeof(Elf64Header)) {
2526
return false;
2627
}
2728

@@ -150,12 +151,14 @@ class ElfParser {
150151
const uint8_t** section,
151152
uint64_t* section_size) const {
152153
PTI_ASSERT(section != nullptr && section_size != nullptr);
153-
if (data_ == nullptr || size_ != sizeof(Elf64Header)) {
154+
if (data_ == nullptr || size_ < sizeof(Elf64Header)) {
155+
*section = nullptr;
156+
*section_size = 0;
154157
return;
155158
}
156159

157160
const Elf64Header* header = reinterpret_cast<const Elf64Header*>(data_);
158-
PTI_ASSERT(data_ + (header->shoff*sizeof(Elf64SectionHeader)) <= data_ + size_);
161+
PTI_ASSERT(data_ + header->shoff + sizeof(Elf64SectionHeader) <= data_ + size_);
159162
const Elf64SectionHeader* section_header =
160163
reinterpret_cast<const Elf64SectionHeader*>(data_ + header->shoff);
161164

utils/gen_symbols_decoder.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ class GenSymbolsDecoder {
6666
reinterpret_cast<const iOpenCL::SProgramDebugDataHeaderIGC*>(ptr);
6767
ptr += sizeof(iOpenCL::SProgramDebugDataHeaderIGC);
6868

69+
PTI_ASSERT(header->NumberOfKernels <= IGC_MAX_VALUE);
70+
6971
for (uint32_t i = 0; i < header->NumberOfKernels; ++i) {
7072
const iOpenCL::SKernelDebugDataHeaderIGC* kernel_header =
7173
reinterpret_cast<const iOpenCL::SKernelDebugDataHeaderIGC*>(ptr);
@@ -103,4 +105,4 @@ class GenSymbolsDecoder {
103105
size_t size_ = 0;
104106
};
105107

106-
#endif // PTI_UTILS_GEN_SYMBOLS_DECODER_H_
108+
#endif // PTI_UTILS_GEN_SYMBOLS_DECODER_H_

0 commit comments

Comments
 (0)