Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Fix build errors due to low kernel version #1838

Merged
merged 1 commit into from Nov 3, 2023

Conversation

MichelleJin12
Copy link
Contributor

@MichelleJin12 MichelleJin12 commented Oct 28, 2023

EM_RISCV, TRACEFS_MAGIC, MAP_FIXED_NOREPLACE macros are added to fix build errors
since they are not declared in the low kernel version.

The error messages are below:

uftrace/cmds/record.c:1592:75: error: ‘EM_RISCV’ undeclared (first use in this function)
  uint16_t supported_machines[] = { EM_X86_64, EM_ARM, EM_AARCH64, EM_386, EM_RISCV };
                                                                           ^
uftrace/utils/tracefs.c:26:53: error: ‘TRACEFS_MAGIC’ undeclared (first use in this function)
  if (!statfs(TRACEFS_DIR_PATH, &fs) && fs.f_type == TRACEFS_MAGIC) {
                                                     ^
uftrace/arch/x86_64/mcount-dynamic.c:46:6: error: ‘MAP_FIXED_NOREPLACE’ undeclared (first use in this function)
      MAP_FIXED_NOREPLACE | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
      ^

Fixed: #1834

Signed-off-by: Michelle Jin shjy180909@gmail.com

Copy link
Owner

@namhyung namhyung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@paranlee
Copy link
Contributor

LGTM too :)

@namhyung
Copy link
Owner

@MichelleJin12 is this working correctly on the old machines? I'm curious about the dynamic tracing part.

@MichelleJin12
Copy link
Contributor Author

@namhyung The version of gcc of my old machine is 4.8.5 and the fpatchable-function-entry option was introduced in gcc 8.5.

I can't verify that dynamic tracing is working correctly because I can't upgrade the gcc version on my old machine due to security problems... I'll try to find a way to check dynamic tracing working correctly.

@MichelleJin12
Copy link
Contributor Author

I created a VM with a ubuntu 14.04 image to test on a lower kernel version.

My environment is

$ uname -a
Linux ubuntu1404 4.4.0-148-generic #174~14.04.1-Ubuntu SMP Thu May 9 08:17:37 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

$ gcc --version
gcc (Ubuntu 4.8.4-2ubuntu1~14.04.4) 4.8.4

I get another error like this:

In file included from /home/jsh/uftrace/utils/argspec.h:5:0,
                 from /home/jsh/uftrace/utils/filter.h:9,
                 from /home/jsh/uftrace/uftrace.h:10,
                 from /home/jsh/uftrace/utils/auto-args.c:8:
/home/jsh/uftrace/utils/rbtree.h:76:10: error: initializer element is not constant
  (struct rb_root)                                                                           \
          ^
/home/jsh/uftrace/utils/auto-args.c:19:38: note: in expansion of macro 'RB_ROOT'
 static struct rb_root auto_argspec = RB_ROOT;
                                      ^
/home/jsh/uftrace/utils/rbtree.h:76:10: error: initializer element is not constant
  (struct rb_root)                                                                           \
          ^
/home/jsh/uftrace/utils/auto-args.c:20:38: note: in expansion of macro 'RB_ROOT'
 static struct rb_root auto_retspec = RB_ROOT;
                                      ^
/home/jsh/uftrace/utils/rbtree.h:76:10: error: initializer element is not constant
  (struct rb_root)                                                                           \
          ^
/home/jsh/uftrace/utils/auto-args.c:21:35: note: in expansion of macro 'RB_ROOT'
 static struct rb_root auto_enum = RB_ROOT;
                                   ^
make: *** [/home/jsh/uftrace/utils/auto-args.o] Error 1

@namhyung
Copy link
Owner

Hmm.. ok. I didn't want to test -fpatchable-function-entry, just plain dynamic tracing without any recompilation. Because the kernel may not understand MAP_FIXED_NOREPLACE even if it's in a numeric form. According to the man page, it's added in v4.17 which is released in June, 2018. Older systems won't understand that so we need to fallback to the original MAP_FIXED in that case. Please see #1798. And now I see that you need to update old affected archs like aarch64 and i386 too.

#ifndef MAP_FIXED_NOREPLACE
#define MAP_FIXED_NOREPLACE MAP_FIXED
#endif

@namhyung
Copy link
Owner

For RB_ROOT failures, I don't know.. it seems the compiler is too old. :-(

@MichelleJin12
Copy link
Contributor Author

MichelleJin12 commented Nov 1, 2023

I found a way to upgrade the gcc version and ran runtest.py on kernel 3.10.
The 223 testcase is for dynamic tracing, but it fails.

cat failed-tests.txt
Compiler                  gcc                                           clang                                       
Runtime test case         pg             finstrument-fu fpatchable-fun  pg             finstrument-fu fpatchable-fun
------------------------: O0 O1 O2 O3 Os O0 O1 O2 O3 Os O0 O1 O2 O3 Os  O0 O1 O2 O3 Os O0 O1 O2 O3 Os O0 O1 O2 O3 Os
...
223 dynamic_full        : NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ  NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ
224 dynamic_lib         : NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ  NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ
225 dynamic_size        : NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ  NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ
...

Even if I modify like below, it fails, too.

#ifndef MAP_FIXED_NOREPLACE
#define MAP_FIXED_NOREPLACE MAP_FIXED
#endif

runtest.py output:

build command: clang -o t-dynamic -fno-inline -fno-builtin -fno-ipa-cp -fno-omit-frame-pointer -D_FORTIFY_SOURCE=0   -Os -fno-pie -fno-plt  s-dynamic.c   
test command: uftrace/uftrace live --no-pager --no-event --libmcount-path=uftrace  -P main -P foo -P bar --no-libcall -N memcpy t-dynamic
WARN: cannot open record data: /tmp/uftrace-live-UJmU9s: No data available
223 dynamic_full        : NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ  NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ NZ

The record command fails.

$ ./uftrace --libmcount-path=. record -v -P main a.out
uftrace: running uftrace v0.14-64-gd36f ( x86_64 dwarf python3 perf sched )
uftrace: checking binary a.out
uftrace: removing uftrace.data.old directory
uftrace: using ./libmcount/libmcount.so library for tracing
uftrace: creating 18 thread(s) for recording
mcount: initializing mcount library
dynamic: dynamic patch type: a.out: 0 (none)
dynamic: dynamic patch stats for 'a.out'
dynamic:    total:        1
dynamic:  patched:        0 ( 0.00%)
dynamic:   failed:        1 (100.00%)
dynamic:  skipped:        0 ( 0.00%)
dynamic: no match:        0
plthook: setup PLT hooking "uftrace/a.out"
mcount: mcount setup done
mcount: new session started: b6ad79d724a7b751: a.out
mcount: mcount trace finished
mcount: exit from libmcount
uftrace: child terminated with exit code: 0
uftrace: cannot read build-id section
uftrace: reading uftrace.data/task.txt file
uftrace: flushing /uftrace-b6ad79d724a7b751-981371-000

$ ./uftrace replay
WARN: cannot open record data: uftrace.data: No data available

EM_RISCV, TRACEFS_MAGIC, MAP_FIXED_NOREPLACE macros are added to
fix build errors since they are not declared in the low kernel version.

The error messages are below:
uftrace/cmds/record.c:1592:75: error: ‘EM_RISCV’ undeclared
(first use in this function)
  uint16_t supported_machines[] = { EM_X86_64, EM_ARM, EM_AARCH64, EM_386, EM_RISCV };
                                                                           ^
uftrace/utils/tracefs.c:26:53: error: ‘TRACEFS_MAGIC’ undeclared
(first use in this function)
  if (!statfs(TRACEFS_DIR_PATH, &fs) && fs.f_type == TRACEFS_MAGIC) {
                                                     ^
uftrace/arch/x86_64/mcount-dynamic.c:46:6: error: ‘MAP_FIXED_NOREPLACE’
undeclared (first use in this function)
      MAP_FIXED_NOREPLACE | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
      ^

Fixed: namhyung#1834

Signed-off-by: Michelle Jin <shjy180909@gmail.com>
@namhyung
Copy link
Owner

namhyung commented Nov 2, 2023

Ok, thanks for the test. I think it's good now.

@namhyung namhyung merged commit c320412 into namhyung:master Nov 3, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

build error due to low kernel version
3 participants