llvm-project/lld/test/ELF/linkerscript/operators.test

147 lines
4.8 KiB
Plaintext

# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64 /dev/null -o %t.o
# RUN: ld.lld %t.o -T %s -o %t
# RUN: llvm-nm -p %t | FileCheck %s
SECTIONS {
_start = .;
plus = 1 + 2 + 3;
minus = 5 - 1;
div = 6 / 2;
mod = 20 % 7;
mul = 1 + 2 * 3;
nospace = 1+2*6/3;
braces = 1 + (2 + 3) * 4;
and = 0xbb & 0xee;
ternary1 = 1 ? 1 : 2;
ternary2 = 0 ? 1 : 2;
less = 1 < 0 ? 1 : 2;
lesseq = 1 <= 1 ? 1 : 2;
greater = 0 > 1 ? 1 : 2;
greatereq = 1 >= 1 ? 1 : 2;
eq = 1 == 1 ? 1 : 2;
neq = 1 != 1 ? 1 : 2;
plusassign = 1;
plusassign += 2;
unary = -1 + 3;
lshift = 1 << 5;
rshift = 0xff >> 3;
precedence1 = 1 | 0xff & 1 << 1 + 1 * 2;
precedence2 = (1 | (0xff & (1 << (1 + (1 * 2)))));
maxpagesize = CONSTANT (MAXPAGESIZE);
commonpagesize = CONSTANT (COMMONPAGESIZE);
. = 0xfff0;
datasegmentalign = DATA_SEGMENT_ALIGN (0xffff, 0);
datasegmentalign2 = DATA_SEGMENT_ALIGN (0, 0);
_end = .;
minus_rel = _end - 0x10;
minus_abs = _end - _start;
max = MAX(11, 22);
min = MIN(11, 22);
log2ceil0 = LOG2CEIL(0);
log2ceil1 = LOG2CEIL(1);
log2ceil2 = LOG2CEIL(2);
log2ceil3 = LOG2CEIL(3);
log2ceil4 = LOG2CEIL(4);
log2ceil100000000 = LOG2CEIL(0x100000000);
log2ceil100000001 = LOG2CEIL(0x100000001);
log2ceilmax = LOG2CEIL(0xffffffffffffffff);
logicaland1 = 0 && 0;
logicaland2 = 0 && 1;
logicaland3 = 1 && 0;
logicaland4 = 1 && 1;
logicalor1 = 0 || 0;
logicalor2 = 0 || 1;
logicalor3 = 1 || 0;
logicalor4 = 1 || 1;
}
# CHECK: 00000000000006 A plus
# CHECK-NEXT: 00000000000004 A minus
# CHECK-NEXT: 00000000000003 A div
# CHECK-NEXT: 00000000000006 A mod
# CHECK-NEXT: 00000000000007 A mul
# CHECK-NEXT: 00000000000005 A nospace
# CHECK-NEXT: 00000000000015 A braces
# CHECK-NEXT: 000000000000aa A and
# CHECK-NEXT: 00000000000001 A ternary1
# CHECK-NEXT: 00000000000002 A ternary2
# CHECK-NEXT: 00000000000002 A less
# CHECK-NEXT: 00000000000001 A lesseq
# CHECK-NEXT: 00000000000002 A greater
# CHECK-NEXT: 00000000000001 A greatereq
# CHECK-NEXT: 00000000000001 A eq
# CHECK-NEXT: 00000000000002 A neq
# CHECK-NEXT: 00000000000003 A plusassign
# CHECK-NEXT: 00000000000002 A unary
# CHECK-NEXT: 00000000000020 A lshift
# CHECK-NEXT: 0000000000001f A rshift
# CHECK-NEXT: 00000000000009 A precedence1
# CHECK-NEXT: 00000000000009 A precedence2
# CHECK-NEXT: 00000000001000 A maxpagesize
# CHECK-NEXT: 00000000001000 A commonpagesize
# CHECK-NEXT: 0000000000ffff A datasegmentalign
# CHECK-NEXT: 0000000000fff0 A datasegmentalign2
# CHECK-NEXT: 0000000000ffe0 T minus_rel
# CHECK-NEXT: 0000000000fff0 A minus_abs
# CHECK-NEXT: 00000000000016 A max
# CHECK-NEXT: 0000000000000b A min
# CHECK-NEXT: 0000000000000000 A log2ceil0
# CHECK-NEXT: 0000000000000000 A log2ceil1
# CHECK-NEXT: 0000000000000001 A log2ceil2
# CHECK-NEXT: 0000000000000002 A log2ceil3
# CHECK-NEXT: 0000000000000002 A log2ceil4
# CHECK-NEXT: 0000000000000020 A log2ceil100000000
# CHECK-NEXT: 0000000000000021 A log2ceil100000001
# CHECK-NEXT: 0000000000000040 A log2ceilmax
# CHECK-NEXT: 00000000000000 A logicaland1
# CHECK-NEXT: 00000000000000 A logicaland2
# CHECK-NEXT: 00000000000000 A logicaland3
# CHECK-NEXT: 00000000000001 A logicaland4
# CHECK-NEXT: 00000000000000 A logicalor1
# CHECK-NEXT: 00000000000001 A logicalor2
# CHECK-NEXT: 00000000000001 A logicalor3
# CHECK-NEXT: 00000000000001 A logicalor4
## Mailformed number error.
# RUN: echo "SECTIONS { . = 0x12Q41; }" > %t.script
# RUN: not ld.lld %t.o -T %t.script -o /dev/null 2>&1 | \
# RUN: FileCheck --check-prefix=NUMERR %s
# NUMERR: malformed number: 0x12Q41
## Missing closing bracket.
# RUN: echo "SECTIONS { . = (1; }" > %t.script
# RUN: not ld.lld %t.o -T %t.script -o /dev/null 2>&1 | \
# RUN: FileCheck --check-prefix=BRACKETERR %s
# BRACKETERR: ) expected, but got ;
## Missing opening bracket.
# RUN: echo "SECTIONS { . = 1); }" > %t.script
# RUN: not ld.lld %t.o -T %t.script -o /dev/null 2>&1 | \
# RUN: FileCheck --check-prefix=BRACKETERR2 %s
# BRACKETERR2: ; expected, but got )
## Empty expression.
# RUN: echo "SECTIONS { . = ; }" > %t.script
# RUN: not ld.lld %t.o -T %t.script -o /dev/null 2>&1 | \
# RUN: FileCheck --check-prefix=ERREXPR %s
# ERREXPR: malformed number: ;
## Div by zero error.
# RUN: echo "SECTIONS { . = 1 / 0; }" > %t.script
# RUN: not ld.lld %t.o -T %t.script -o /dev/null 2>&1 | \
# RUN: FileCheck --check-prefix=DIVZERO %s
# DIVZERO: {{.*}}.script:1: division by zero
## Mod by zero error.
# RUN: echo "SECTIONS { . = 1 % 0; }" > %t.script
# RUN: not ld.lld %t.o -T %t.script -o /dev/null 2>&1 | \
# RUN: FileCheck --check-prefix=MODZERO %s
# MODZERO: {{.*}}.script:1: modulo by zero
## Broken ternary operator expression.
# RUN: echo "SECTIONS { . = 1 ? 2; }" > %t.script
# RUN: not ld.lld %t.o -T %t.script -o /dev/null 2>&1 | \
# RUN: FileCheck --check-prefix=TERNERR %s
# TERNERR: : expected, but got ;