brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.8 KiB · c76be48 Raw
58 lines · plain
1; REQUIRES: x862; This test intentionally checks for fatal errors, and fatal errors aren't supported for testing when main is run twice.3; XFAIL: main-run-twice4 5;; The LLVM bitcode format allows for an optional wrapper header. This test6;; shows that LLD can handle bitcode wrapped in this way, and also that an7;; invalid offset in the wrapper header is handled cleanly.8 9; RUN: rm -rf %t10; RUN: split-file %s %t11; RUN: llvm-as %t/ir.ll -o %t.bc12 13;; Basic case:14; RUN: %python %t/wrap_bitcode.py %t.bc %t.o 0 0x1415; RUN: ld.lld %t.o -o %t.elf16; RUN: llvm-readelf -s %t.elf | FileCheck %s17 18;; Padding between wrapper header and body:19; RUN: %python %t/wrap_bitcode.py %t.bc %t.o 0x10 0x2420; RUN: ld.lld %t.o -o %t.elf21; RUN: llvm-readelf -s %t.elf | FileCheck %s22 23; CHECK: _start24 25;; Invalid offset past end of file:26; RUN: %python %t/wrap_bitcode.py %t.bc %t2.o 0x10 0xffffffff27; RUN: not ld.lld %t2.o -o %t2.elf 2>&1 | FileCheck %s --check-prefix=ERR1 -DFILE=%t2.o28 29; ERR1: error: [[FILE]]: Invalid bitcode wrapper header30 31;; Invalid offset within file:32; RUN: %python %t/wrap_bitcode.py %t.bc %t3.o 0x10 0x1433; RUN: not ld.lld %t3.o -o %t3.elf 2>&1 | FileCheck %s --check-prefix=ERR2 -DFILE=%t3.o34 35; ERR2: error: [[FILE]]: file doesn't start with bitcode header36 37;--- ir.ll38target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"39target triple = "x86_64-unknown-linux-gnu"40 41@_start = global i32 042 43;--- wrap_bitcode.py44## Arguments are: input file, output file, padding size, offset value.45import struct46import sys47 48with open(sys.argv[1], 'rb') as input:49    bitcode = input.read()50 51padding = int(sys.argv[3], 16) * b'\0'52offset = int(sys.argv[4], 16)53header = struct.pack('<IIIII', 0x0B17C0DE, 0, offset, len(bitcode), 0)54with open(sys.argv[2], 'wb') as output:55    output.write(header)56    output.write(padding)57    output.write(bitcode)58