Skip to content

Commit e21b75d

Browse files
authored
kptools: Support compile kptools for windows target (#37)
* kptools: Support compile for windows target * ci: Support build for windows mingw32
1 parent ee09601 commit e21b75d

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

.github/workflows/build.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,52 @@ jobs:
215215
allowUpdates: true
216216
replacesArtifacts: true
217217

218+
Build-kptools-windows:
219+
runs-on: ubuntu-latest
220+
permissions:
221+
contents: write
222+
steps:
223+
- name: Check out
224+
uses: actions/checkout@v3
225+
- name: Install mingw32 cross toolchains
226+
run: |
227+
MINGW_LLVM_URL="https://github.com/mstorsjo/llvm-mingw/releases/download/20231128/llvm-mingw-20231128-msvcrt-ubuntu-20.04-x86_64.tar.xz"
228+
mkdir -p $HOME/mingw-llvm
229+
wget $MINGW_LLVM_URL -O $HOME/mingw-llvm/llvm.tar.xz
230+
cd $HOME/mingw-llvm
231+
tar -xvf llvm.tar.xz --strip-components 1
232+
- name: Generate version
233+
id: parse_version
234+
run: |
235+
MAJOR=$(grep '#define MAJOR' version | awk '{print $3}')
236+
MINOR=$(grep '#define MINOR' version | awk '{print $3}')
237+
PATCH=$(grep '#define PATCH' version | awk '{print $3}')
238+
VERSION="$MAJOR.$MINOR.$PATCH"
239+
echo "Generated Version: $VERSION"
240+
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
241+
- name: Build kptools
242+
run: |
243+
export PATH="$HOME/mingw-llvm/bin:$PATH"
244+
export ANDROID=1
245+
ABIS="x86_64 i686 aarch64 armv7"
246+
for i in $ABIS; do
247+
make -C kernel hdr TARGET_COMPILE=placeholder
248+
echo "- Compiling kptools-$i-win.exe"
249+
make -C tools CC=$i-w64-mingw32-clang
250+
mv tools/kptools.exe kptools-$i-win.exe
251+
make -C tools clean
252+
done
253+
7za a kptools-win.zip -tZIP *.exe
254+
- name: Release
255+
uses: ncipollo/release-action@v1.12.0
256+
with:
257+
token: ${{ secrets.GITHUB_TOKEN }}
258+
tag: ${{ steps.parse_version.outputs.VERSION }}
259+
artifacts: |
260+
kptools-win.zip
261+
allowUpdates: true
262+
replacesArtifacts: true
263+
218264
Build-kptools-mac:
219265
runs-on: macos-latest
220266
permissions:

tools/kallsym.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,27 @@ typedef struct
105105

106106
} kallsym_t;
107107

108+
#ifdef _WIN32
109+
#include <string.h>
110+
static void *memmem(const void *haystack, size_t haystack_len,
111+
const void * const needle, const size_t needle_len)
112+
{
113+
if (haystack == NULL) return NULL; // or assert(haystack != NULL);
114+
if (haystack_len == 0) return NULL;
115+
if (needle == NULL) return NULL; // or assert(needle != NULL);
116+
if (needle_len == 0) return NULL;
117+
118+
for (const char *h = haystack;
119+
haystack_len >= needle_len;
120+
++h, --haystack_len) {
121+
if (!memcmp(h, needle, needle_len)) {
122+
return (void*)h;
123+
}
124+
}
125+
return NULL;
126+
}
127+
#endif
128+
108129
int analyze_kallsym_info(kallsym_t *info, char *img, int32_t imglen, enum arch_type arch, int32_t is_64);
109130
int dump_all_symbols(kallsym_t *info, char *img);
110131
int get_symbol_index_offset(kallsym_t *info, char *img, int32_t index);

0 commit comments

Comments
 (0)