Skip to content

Commit f8de9aa

Browse files
committed
[llvm-rc] Add a GNU windres-like frontend to llvm-rc
This primarily parses a different set of options and invokes the same resource compiler as llvm-rc normally. Additionally, it can convert directly to an object file (which in MSVC style setups is done with the separate cvtres tool, or by the linker). (GNU windres also supports other conversions; from coff object file back to .res, and from .res or object file back to .rc form; that's not yet implemented.) The other bigger complication lies in being able to imply or pass the intended target triple, to let clang find the corresponding mingw sysroot for finding include files, and for specifying the default output object machine format. It can be implied from the tool triple prefix, like `<triple>-[llvm-]windres` or picked up from the windres option e.g. `-F pe-x86-64`. In GNU windres, that option takes BFD style format names such as pe-i386 or pe-x86-64. As libbfd in binutils doesn't support Windows on ARM, there's no such canonical name for the ARM targets. Therefore, as an LLVM specific extension, this option is extended to allow passing full triples, too. Differential Revision: https://reviews.llvm.org/D100756
1 parent f0c22c3 commit f8de9aa

File tree

15 files changed

+715
-104
lines changed

15 files changed

+715
-104
lines changed

clang/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ if( NOT CLANG_BUILT_STANDALONE )
125125
llvm-readobj
126126
llvm-strip
127127
llvm-symbolizer
128+
llvm-windres
128129
opt
129130
split-file
130131
yaml2obj
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef RC_INVOKED
2+
#error RC_INVOKED not defined
3+
#endif
4+
#ifndef _WIN32
5+
#error _WIN32 not defined
6+
#endif
7+
#ifndef __MINGW32__
8+
#error __MINGW32__ not defined
9+
#endif
10+
#define MY_ID 42
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: llvm-windres -I%p/Inputs %s %t.res
2+
// RUN: llvm-readobj %t.res | FileCheck %s
3+
// CHECK: Resource type (int): RCDATA (ID 10)
4+
// CHECK: Resource name (int): 42
5+
#include "llvm-windres.h"
6+
MY_ID RCDATA {
7+
"a long string of data"
8+
}

llvm/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ set(LLVM_TEST_DEPENDS
117117
llvm-symbolizer
118118
llvm-tblgen
119119
llvm-undname
120+
llvm-windres
120121
llvm-xray
121122
not
122123
obj2yaml

llvm/test/lit.cfg.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ def get_asan_rtlib():
163163
'llvm-modextract', 'llvm-nm', 'llvm-objcopy', 'llvm-objdump', 'llvm-otool',
164164
'llvm-pdbutil', 'llvm-profdata', 'llvm-profgen', 'llvm-ranlib', 'llvm-rc', 'llvm-readelf',
165165
'llvm-readobj', 'llvm-rtdyld', 'llvm-size', 'llvm-split', 'llvm-strings',
166-
'llvm-strip', 'llvm-tblgen', 'llvm-undname', 'llvm-c-test', 'llvm-cxxfilt',
166+
'llvm-strip', 'llvm-tblgen', 'llvm-undname', 'llvm-windres',
167+
'llvm-c-test', 'llvm-cxxfilt',
167168
'llvm-xray', 'yaml2obj', 'obj2yaml', 'yaml-bench', 'verify-uselistorder',
168169
'bugpoint', 'llc', 'llvm-symbolizer', 'opt', 'sancov', 'sanstats'])
169170

llvm/test/tools/llvm-rc/codepage.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
; RUN: llvm-rc -no-preprocess /C 65001 /FO %t.utf8.res -- %p/Inputs/utf8.rc
22
; RUN: llvm-readobj %t.utf8.res | FileCheck %s --check-prefix=UTF8
3+
; RUN: llvm-windres --no-preprocess -c 65001 %p/Inputs/utf8.rc %t.utf8.res
4+
; RUN: llvm-readobj %t.utf8.res | FileCheck %s --check-prefix=UTF8
5+
; RUN: llvm-windres --no-preprocess --codepage 65001 %p/Inputs/utf8.rc %t.utf8.res
6+
; RUN: llvm-readobj %t.utf8.res | FileCheck %s --check-prefix=UTF8
37

48
; UTF8: Resource type (int): STRINGTABLE (ID 6)
59
; UTF8-NEXT: Resource name (int): 1
@@ -24,6 +28,8 @@
2428

2529
; RUN: llvm-rc -no-preprocess /C 1252 /FO %t.cp1252.res -- %p/Inputs/cp1252.rc
2630
; RUN: llvm-readobj %t.cp1252.res | FileCheck %s --check-prefix=CP1252
31+
; RUN: llvm-windres --no-preprocess -c 1252 %p/Inputs/cp1252.rc %t.cp1252.res
32+
; RUN: llvm-readobj %t.cp1252.res | FileCheck %s --check-prefix=CP1252
2733

2834
; CP1252: Resource type (int): STRINGTABLE (ID 6)
2935
; CP1252-NEXT: Resource name (int): 1

llvm/test/tools/llvm-rc/language.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
; RUN: llvm-readobj %t.res | FileCheck %s
33
; RUN: llvm-rc -no-preprocess /l40A /FO %t.res -- %p/Inputs/language.rc
44
; RUN: llvm-readobj %t.res | FileCheck %s
5+
; RUN: llvm-windres --no-preprocess -l 40A %p/Inputs/language.rc %t.res
6+
; RUN: llvm-readobj %t.res | FileCheck %s
7+
; RUN: llvm-windres --no-preprocess --language 40A %p/Inputs/language.rc %t.res
8+
; RUN: llvm-readobj %t.res | FileCheck %s
59

610
; CHECK: Resource name (int): 1
711
; CHECK-NEXT: Data version:
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
; Check that the various input/output formats (rc/res/coff) are implied
2+
; from file suffixes.
3+
4+
; RUN: rm -f %t.res
5+
; RUN: llvm-windres --no-preprocess %p/Inputs/tag-stringtable-basic.rc %t.res
6+
; RUN: llvm-readobj %t.res | FileCheck %s --check-prefix=CHECK-RES
7+
8+
; RUN: rm -f %t.o
9+
; RUN: llvm-windres --no-preprocess -F pe-x86-64 %p/Inputs/tag-stringtable-basic.rc %t.o
10+
; RUN: llvm-readobj --coff-resources %t.o | FileCheck %s --check-prefix=CHECK-OBJ
11+
12+
; RUN: rm -f %t.obj
13+
; RUN: llvm-windres -F pe-x86-64 %t.res %t.obj
14+
; RUN: llvm-readobj --coff-resources %t.obj | FileCheck %s --check-prefix=CHECK-OBJ
15+
16+
; Check that we can specify the input/output file types explicitly.
17+
; Also check options for specifying the input/output file names.
18+
19+
; RUN: cat %p/Inputs/tag-stringtable-basic.rc > %t-anonymous
20+
; RUN: rm -f %t-anonymous2
21+
; RUN: llvm-windres --no-preprocess -O res -J rc -o %t-anonymous2 -i %t-anonymous
22+
; RUN: llvm-readobj %t-anonymous2 | FileCheck %s --check-prefix=CHECK-RES
23+
24+
; RUN: rm -f %t-anonymous3
25+
; RUN: llvm-windres -F pe-x86-64 -J res -O coff -i%t-anonymous2 -o%t-anonymous3
26+
; RUN: llvm-readobj --coff-resources %t-anonymous3 | FileCheck %s --check-prefix=CHECK-OBJ
27+
28+
; CHECK-RES: Resource type (int): STRINGTABLE
29+
30+
; CHECK-OBJ: Format: COFF-x86-64
31+
; CHECK-OBJ: Resources [
32+
; CHECK-OBJ: Total Number of Resources:
33+
34+
; Check for format conversions that currently aren't supported.
35+
36+
; RUN: not llvm-windres -F pe-x86-64 -J res -O rc -i%t-anonymous2 -o%t-anonymous 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR-OUTPUT
37+
; RUN: not llvm-windres -F pe-x86-64 -J coff -O res -i%t-anonymous3 -o%t-anonymous2 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR-INPUT
38+
39+
; CHECK-ERROR-OUTPUT: Unsupported output format
40+
; CHECK-ERROR-INPUT: Unsupported input format
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; REQUIRES: shell
2+
3+
; RUN: rm -rf %t && mkdir %t
4+
5+
; Check that a triple prefix on the executable gets picked up as target triple.
6+
7+
; RUN: ln -fs $(which llvm-windres) %t/aarch64-w64-mingw32-windres
8+
; RUN: %t/aarch64-w64-mingw32-windres -### %p/Inputs/empty.rc %t.res | FileCheck %s --check-prefix=CHECK-PREPROC
9+
; CHECK-PREPROC: "clang" "--driver-mode=gcc" "-target" "aarch64-w64-mingw32"
10+
11+
; Check that the triple prefix also affects the output object file type.
12+
13+
; RUN: %t/aarch64-w64-mingw32-windres --no-preprocess %p/Inputs/tag-stringtable-basic.rc %t.o
14+
; RUN: llvm-readobj --coff-resources %t.o | FileCheck %s --check-prefix=CHECK-OBJ
15+
16+
; CHECK-OBJ: Format: COFF-ARM64
17+
; CHECK-OBJ: Resources [
18+
; CHECK-OBJ: Total Number of Resources:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
; RUN: llvm-windres -### --include-dir %p/incdir1 --include %p/incdir2 "-DFOO1=\\\"foo bar\\\"" -UFOO2 -D FOO3 --preprocessor-arg "-DFOO4=\\\"baz baz\\\"" %p/Inputs/empty.rc %t.res | FileCheck %s --check-prefix=CHECK1
2+
; CHECK1: {{^}} "clang" "--driver-mode=gcc" "-target" "{{.*}}-w64-mingw32" "-E" "-xc" "-DRC_INVOKED" "{{.*}}empty.rc" "-o" "{{.*}}preproc-{{.*}}.rc" "-I" "{{.*}}incdir1" "-I" "{{.*}}incdir2" "-D" "FOO1=\"foo bar\"" "-U" "FOO2" "-D" "FOO3" "-DFOO4=\"baz baz\""{{$}}
3+
; RUN: llvm-windres -### --preprocessor "i686-w64-mingw32-gcc -E -DFOO=\\\"foo\\ bar\\\"" %p/Inputs/empty.rc %t.res | FileCheck %s --check-prefix=CHECK2
4+
; CHECK2: {{^}} "i686-w64-mingw32-gcc" "-E" "-DFOO=\"foo bar\"" "{{.*}}empty.rc" "-o" "{{.*}}preproc-{{.*}}.rc"{{$}}

0 commit comments

Comments
 (0)