Skip to content

Commit 37e386f

Browse files
authored
Merge pull request #114 from hackeris/x86-64
x86_64 target: fix compile error of gdb and kbd for x86_64
2 parents d1f6d00 + 82d4688 commit 37e386f

4 files changed

Lines changed: 137 additions & 0 deletions

File tree

build-hnp/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ PKGS=gettext \
9696
readline \
9797
htop \
9898
vkpeak \
99+
kbd \
99100
libevent \
100101
tmux \
101102
fish \
@@ -108,6 +109,7 @@ PKGS=gettext \
108109
git \
109110
aria2 \
110111
xz \
112+
gdb \
111113
python \
112114
libusb \
113115
hdc \

build-hnp/gdb/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,10 @@ SOURCE_URL = $(GNU_MIRROR)/gnu/gdb/gdb-16.3.tar.xz
44
SOURCE_FILE = gdb-16.3.tar.xz
55
SOURCE_DIR = gdb-16.3
66
CONFIG_ARGS = --prefix=$(PREFIX) --with-lzma --disable-sim --disable-static --enable-shared --with-system-readline --host $(OHOS_ARCH)-unknown-linux-musl --disable-nls
7+
ifeq ($(OHOS_ARCH),x86_64)
8+
PATCH_SOURCE = cd temp/$(SOURCE_DIR) \
9+
&& cat ../../linux-btrace.diff | patch -Np1 \
10+
&& cat ../../linux-amd64-ipa.patch | patch -Np1
11+
endif
712

813
$(eval $(call define_autotools_package))
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--- a/gdbserver/linux-amd64-ipa.cc 2025-04-21 01:22:06.000000000 +0800
2+
+++ b/gdbserver/linux-amd64-ipa.cc 2025-08-28 00:04:25.067615107 +0800
3+
@@ -233,7 +233,7 @@
4+
return NULL;
5+
#else
6+
void *res = mmap (NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC,
7+
- MAP_PRIVATE | MAP_ANONYMOUS | MAP_32BIT, -1, 0);
8+
+ MAP_PRIVATE | MAP_ANONYMOUS , -1, 0);
9+
10+
if (res == MAP_FAILED)
11+
return NULL;

build-hnp/gdb/linux-btrace.diff

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
--- a/gdb/nat/linux-btrace.c 2025-04-21 01:22:05.000000000 +0800
2+
+++ b/gdb/nat/linux-btrace.c 2025-08-26 10:04:03.839124442 +0800
3+
@@ -30,6 +30,7 @@
4+
#include <inttypes.h>
5+
6+
#include <sys/syscall.h>
7+
+#include <unistd.h>
8+
9+
#if HAVE_LINUX_PERF_EVENT_H && defined(SYS_perf_event_open)
10+
#include <unistd.h>
11+
@@ -516,6 +517,8 @@
12+
__u64 data_offset;
13+
int pid, pg;
14+
15+
+ long page_size = sysconf(_SC_PAGESIZE);
16+
+
17+
if (!cpu_supports_bts ())
18+
error (_("BTS support has been disabled for the target cpu."));
19+
20+
@@ -546,8 +549,8 @@
21+
diagnose_perf_event_open_fail ();
22+
23+
/* Convert the requested size in bytes to pages (rounding up). */
24+
- pages = ((size_t) conf->size / PAGE_SIZE
25+
- + ((conf->size % PAGE_SIZE) == 0 ? 0 : 1));
26+
+ pages = ((size_t) conf->size / page_size
27+
+ + ((conf->size % page_size) == 0 ? 0 : 1));
28+
/* We need at least one page. */
29+
if (pages == 0)
30+
pages = 1;
31+
@@ -566,17 +569,17 @@
32+
size_t length;
33+
__u64 data_size;
34+
35+
- data_size = (__u64) pages * PAGE_SIZE;
36+
+ data_size = (__u64) pages * page_size;
37+
38+
/* Don't ask for more than we can represent in the configuration. */
39+
if ((__u64) UINT_MAX < data_size)
40+
continue;
41+
42+
size = (size_t) data_size;
43+
- length = size + PAGE_SIZE;
44+
+ length = size + page_size;
45+
46+
/* Check for overflows. */
47+
- if ((__u64) length != data_size + PAGE_SIZE)
48+
+ if ((__u64) length != data_size + page_size)
49+
continue;
50+
51+
errno = 0;
52+
@@ -591,7 +594,7 @@
53+
54+
struct perf_event_mmap_page *header = (struct perf_event_mmap_page *)
55+
data.get ();
56+
- data_offset = PAGE_SIZE;
57+
+ data_offset = page_size;
58+
59+
#if defined (PERF_ATTR_SIZE_VER5)
60+
if (offsetof (struct perf_event_mmap_page, data_size) <= header->size)
61+
@@ -664,6 +667,8 @@
62+
size_t pages;
63+
int pid, pg;
64+
65+
+ long page_size = sysconf(_SC_PAGESIZE);
66+
+
67+
pid = ptid.lwp ();
68+
if (pid == 0)
69+
pid = ptid.pid ();
70+
@@ -703,7 +708,7 @@
71+
diagnose_perf_event_open_fail ();
72+
73+
/* Allocate the configuration page. */
74+
- scoped_mmap data (nullptr, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED,
75+
+ scoped_mmap data (nullptr, page_size, PROT_READ | PROT_WRITE, MAP_SHARED,
76+
fd.get (), 0);
77+
if (data.get () == MAP_FAILED)
78+
error (_("Failed to map trace user page: %s."), safe_strerror (errno));
79+
@@ -714,8 +719,8 @@
80+
header->aux_offset = header->data_offset + header->data_size;
81+
82+
/* Convert the requested size in bytes to pages (rounding up). */
83+
- pages = ((size_t) conf->size / PAGE_SIZE
84+
- + ((conf->size % PAGE_SIZE) == 0 ? 0 : 1));
85+
+ pages = ((size_t) conf->size / page_size
86+
+ + ((conf->size % page_size) == 0 ? 0 : 1));
87+
/* We need at least one page. */
88+
if (pages == 0)
89+
pages = 1;
90+
@@ -734,7 +739,7 @@
91+
size_t length;
92+
__u64 data_size;
93+
94+
- data_size = (__u64) pages * PAGE_SIZE;
95+
+ data_size = (__u64) pages * page_size;
96+
97+
/* Don't ask for more than we can represent in the configuration. */
98+
if ((__u64) UINT_MAX < data_size)
99+
@@ -805,7 +810,8 @@
100+
static void
101+
linux_disable_bts (struct linux_btrace_target_info *tinfo)
102+
{
103+
- munmap ((void *) tinfo->header, tinfo->pev.size + PAGE_SIZE);
104+
+ long page_size = sysconf(_SC_PAGESIZE);
105+
+ munmap ((void *) tinfo->header, tinfo->pev.size + page_size);
106+
close (tinfo->file);
107+
}
108+
109+
@@ -814,8 +820,9 @@
110+
static void
111+
linux_disable_pt (struct linux_btrace_target_info *tinfo)
112+
{
113+
+ long page_size = sysconf(_SC_PAGESIZE);
114+
munmap ((void *) tinfo->pev.mem, tinfo->pev.size);
115+
- munmap ((void *) tinfo->header, PAGE_SIZE);
116+
+ munmap ((void *) tinfo->header, page_size);
117+
close (tinfo->file);
118+
}
119+

0 commit comments

Comments
 (0)