Skip to content

compile error on LD_PRELOAD version #942

Closed

Description

@zcuder

following instructions by https://cloud.tencent.com/developer/article/2278480 using branch dev
But got compile errors:
./ff_declare_syscalls.h:25:22: error: conflicting types for ‘ioctl’; have ‘int(int, long unsigned int, long unsigned int)’
25 | FF_SYSCALL_DECL(int, ioctl, (int, unsigned long, unsigned long));
| ^~~~~
ff_hook_syscall.c:37:28: note: in definition of macro ‘strong_alias’
37 | extern __typeof (name) aliasname attribute ((alias (#name)));
| ^~~~~~~~~
./ff_declare_syscalls.h:25:1: note: in expansion of macro ‘FF_SYSCALL_DECL’
25 | FF_SYSCALL_DECL(int, ioctl, (int, unsigned long, unsigned long));
| ^~~~~~~~~~~~~~~
In file included from /usr/include/sys/epoll.h:22,
from ff_hook_syscall.c:4:
/usr/include/sys/ioctl.h:42:12: note: previous declaration of ‘ioctl’ with type ‘int(int, long unsigned int, ...)’
42 | extern int ioctl (int __fd, unsigned long int __request, ...) __THROW;
| ^~~~~
make: *** [Makefile:129: ff_hook_syscall.o] Error 1
uname -r
5.15.178-120.180.amzn2.x86_64

It looks to me ioctl has always been variable paramerters. int ioctl (int __fd, unsigned long int __request, ...) https://man7.org/linux/man-pages/man2/ioctl.2.html
I am wondering how actually does this work, and any expert could help fix this?

Activity

  1. jfb8856606 commented on Mar 16, 2026

    @jfb8856606
    Contributor

    Thank you for the detailed report!

    Root Cause Analysis:

    The compile error is caused by a type conflict in adapter/syscall/ff_declare_syscalls.h:

    // Current declaration in f-stack (fixed args):
    FF_SYSCALL_DECL(int, ioctl, (int, unsigned long, unsigned long));
    
    // glibc standard declaration (variadic):
    extern int ioctl (int __fd, unsigned long int __request, ...) __THROW;

    The strong_alias macro expands this into a function declaration with fixed parameters (int, unsigned long, unsigned long), which conflicts with glibc's variadic ioctl(int, unsigned long, ...).

    Newer GCC versions (especially on Amazon Linux 2 / kernel 5.15+) enforce stricter type-checking for __attribute__((alias(...))), causing this error to surface.

    Current Status:

    This issue has not yet been fixed in the dev branch. The ff_declare_syscalls.h file was last modified on 2025-06-08 (only added select support), but the ioctl declaration remains unchanged.

    Suggested Fix:

    Since ioctl is truly variadic in practice, the cleanest fix is to handle it separately rather than through FF_SYSCALL_DECL. One approach:

    1. Remove ioctl from ff_declare_syscalls.h
    2. Declare the alias manually using a wrapper that matches the variadic signature, e.g.:
    // In ff_hook_syscall.c, replace the macro-generated alias with:
    int ioctl(int fd, unsigned long req, ...) __attribute__((alias("ff_hook_ioctl")));

    Or alternatively, change ff_hook_ioctl to also be variadic and use va_arg to extract the third argument.

    Workaround (temporary):

    If you need to compile immediately, you can comment out the ioctl line in ff_declare_syscalls.h and manually add an alias declaration with variadic signature.

    We will track this for a proper fix. Thanks again for the report!

  2. jfb8856606 commented on Mar 17, 2026

    @jfb8856606
    Contributor

    Fix Available — PR #1047

    A fix has been submitted in PR #1047.

    Root Cause (clarified)

    The error is environment-dependent. It triggers when sys/ioctl.h is pulled in transitively (via epoll.h or other headers) before the strong_alias macro expansion in ff_hook_syscall.c.

    • On older glibc (≤ 2.26, e.g. Amazon Linux 2): epoll.h indirectly includes ioctl.h, so ioctl is already declared as variadic when FF_SYSCALL_DECL(int, ioctl, ...) expands → compile error.
    • On newer glibc (≥ 2.38, e.g. TencentOS/Ubuntu 22+): epoll.h does not include ioctl.h → no conflict → compiles fine.

    The underlying issue is that ioctl(2) has a variadic signature in glibc:

    extern int ioctl(int __fd, unsigned long int __request, ...) __THROW;

    but ff_declare_syscalls.h registered it as a fixed-arg function, which is incompatible with strong_alias / __typeof on systems where the variadic declaration is already visible.

    Fix Summary (4 files)

    File Change
    ff_declare_syscalls.h Remove FF_SYSCALL_DECL(int, ioctl, ...)
    ff_hook_syscall.c Add explicit variadic ioctl() wrapper using va_arg, forwarding to ff_hook_ioctl()
    ff_linux_syscall.h Add explicit declaration of ff_linux_ioctl()
    ff_linux_syscall.c Add manual pf_ioctl struct member and dlsym("ioctl") load

    Temporary Workaround

    If you need to compile immediately before the PR is merged, add #include <sys/ioctl.h> at the top of your application and apply a local patch removing the ioctl line from ff_declare_syscalls.h.

  3. jfb8856606 commented on Mar 17, 2026

    @jfb8856606
    Contributor

    Fix Available — PR #1048

    PR #1047 was closed due to incorrect base branch. The correct fix is in PR #1048.

    Root Cause (clarified)

    The error is environment-dependent. It triggers when sys/ioctl.h is pulled in transitively (via epoll.h or other headers) before the strong_alias macro expansion in ff_hook_syscall.c.

    • On older glibc (≤ 2.26, e.g. Amazon Linux 2): epoll.h indirectly includes ioctl.h, so ioctl is already declared as variadic when FF_SYSCALL_DECL(int, ioctl, ...) expands → compile error.
    • On newer glibc (≥ 2.38, e.g. TencentOS/Ubuntu 22+): epoll.h does not include ioctl.h → no conflict → compiles fine.

    The underlying issue is that ioctl(2) has a variadic signature in glibc:

    extern int ioctl(int __fd, unsigned long int __request, ...) __THROW;

    but ff_declare_syscalls.h registered it as a fixed-arg function, which is incompatible with strong_alias / __typeof on systems where the variadic declaration is already visible.

    Fix Summary (4 files)

    File Change
    ff_declare_syscalls.h Remove FF_SYSCALL_DECL(int, ioctl, ...)
    ff_hook_syscall.c Add explicit variadic ioctl() wrapper using va_arg, forwarding to ff_hook_ioctl()
    ff_linux_syscall.h Add explicit declaration of ff_linux_ioctl()
    ff_linux_syscall.c Add manual pf_ioctl struct member and dlsym("ioctl") load

    Temporary Workaround

    If you need to compile immediately before the PR is merged, remove the ioctl line from ff_declare_syscalls.h and apply the changes from PR #1048 manually.

  4. jfb8856606 commented on Mar 17, 2026

    @jfb8856606
    Contributor

    PR #1048 已合并(merge commit: 2958b02),修复了 ioctl conflicting types 在旧版 glibc 上的编译错误,此 issue 现在关闭。

  5. jfb8856606 commented on Mar 18, 2026

    @jfb8856606
    Contributor

    [Manual comment] The above AI analysis of the compile error root cause is not something I fully agree with. The part about build environment differences is correct, but I disagree with the claim that older glibc header trees are responsible. My personal view is that this is more likely a bug in GCC 7.3.1 (the default compiler on Amazon Linux 2), as in my experience that version has known issues with insufficiently precise data-flow analysis that frequently produces false-positive errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions