error: implicit declaration of function 'execl' [-Werror=implicit-function-declaration] - c

I am trying to use execl call to execute a binary in kernel-space-driver (driver.c) at this point(line no. 850 onward):
if (!retval)
{
pr_info("%s: registered new device driver %s\n",
usbcore_name, new_udriver->name);
execl("binarylocation", "binary", NULL);
}
I have also added the #include < linux/unistd.h> in the file.
But when the kernel is build I get the following error:
error: implicit declaration of function 'execl' [-Werror=implicit-function-declaration]
and thus the kernel failed to built.
And one warning is coming:
warning: incompatible implicit declaration of built-in function 'execl' [enabled by default]
Why are these errors and warning coming, even though the required header files are included?

execl is provided by libc, which is user-mode. In addition, exec functions replace the current process, but that context in the kernel doesn't really have a "current process" you'd want to be replacing.
The correct way to do this would be through a udev rule. If you really don't want to use udev for some reason, you can use the usermode helper API (example).

Related

Error: "Implicit declaration" for device_create_with_groups

I am trying to build a custom kernel for NVIDIA Jetson Tk-1 by following the instructions here:
https://github.com/projectara/Android-wiki/wiki/Kernel-Only-Build-Instructions-for-Jetson-reference-platform
Everything goes well until the "Testing Your Custom Kernel" section:
STEP 2. make greybus modules
$ cd $JKB_ROOT/greybus
$ make clean
$ make ARCH=arm KERNELDIR=../kernel-out EXTRA_CFLAGS+=-fno-pic
Here is a snippet for the error I am getting:
/home/jonah/ara_kernel/greybus/loopback.c: In function
'gb_loopback_probe': /home/jonah/ara_kernel/greybus/loopback.c:1207:2:
error: implicit declaration of function 'device_create_with_groups'
[-Werror=implicit-function-declaration] dev =
device_create_with_groups(&loopback_class, ^
/home/jonah/ara_kernel/greybus/loopback.c:1207:6: warning: assignment
makes pointer from integer without a cast [enabled by default] dev =
device_create_with_groups(&loopback_class,
the problem occurs in the loopback.c file, which uses the function device_create_with_groups(...)
Here is the loopback.c file:
https://github.com/projectara/greybus/blob/master/loopback.c
As I understand, this function is found in include/linux/device.h header file, but even if I add #include <linux/device.h> to the beginning of loopback.c, I get the same implicit declaration error.
I am running Ubuntu 14.04 with Linux kernel headers 4.5.0-040500-generic.
Am I using the wrong kernel headers or is the function deprecated or something?
I can get rid of the warning with a declaration in the function above it:
struct device *device_create_with_groups(struct class *class, struct device *parent, dev_t devt, void *drvdata, const struct attribute_group **groups, const char *fmt, ...);
but will this have any severe repercussions when I use the kernel? Or will the function magically be found by the linker eventually?

Implicit declaration of function 'cond_resched' that is defined as macro in included header

I'm trying to build a kernel with some patches that affect the same files and have a problem.
While building, i get an error:
arch/x86/include/asm/uaccess_64.h: In function 'copy_from_user': arch/x86/include/asm/uaccess_64.h:81:2: error: implicit declaration of function 'cond_resched' [-Werror=implicit-function-declaration]
At first i followed the code and found out that the pointed string is:
if (access_ok(VERIFY_READ, from, n))
access_ok(...) is a macro from file uaccess.h, that does include cond_resched() call.
Actual cond_resched() call is defined in linux/sched.h and is #included into uaccess.h file. Also i tried to include it into uaccess_64.h file but it doesn't help. So i'm out of ideas how it could be implicitly declared.

Compilation Error of C code on Linux (Same code compiles on OSX)

I am trying to compile some code on linux that I KNOW compiles on OSX, but I am getting some issues.
All of the files have headers named .h, and all of the files are in the same directory. I am compiling like this:
gcc *.c -std=c99 -lpthread
And while this code does compile on OSX, I get a bunch of weird linker errors on my Ubuntu install. Am I missing a few compiler options? It is a default Ubuntu-server install with the additional packages gcc and build-essential installed.
In file included from errorLogger.h:24:0,
from configParser.h:17,
from configParser.c:9:
signalHandling.h:24:18: error: unknown type name ‘sigset_t’
configParser.c: In function ‘parseConfigFile’:
configParser.c:114:5: warning: implicit declaration of function ‘getline’ [-Wimplicit-function-declaration]
In file included from errorLogger.h:24:0,
from global.h:18,
from connection.h:19,
from connection.c:10:
signalHandling.h:24:18: error: unknown type name ‘sigset_t’
connection.c: In function ‘createConnectionQueue’:
connection.c:189:28: warning: assignment makes integer from pointer without a cast [enabled by default]
In file included from errorLogger.h:24:0,
from database.h:16,
from database.c:9:
signalHandling.h:24:18: error: unknown type name ‘sigset_t’
In file included from errorLogger.h:24:0,
from errorLogger.c:10:
signalHandling.h:24:18: error: unknown type name ‘sigset_t’
errorLogger.c: In function ‘reportError’:
errorLogger.c:63:5: warning: implicit declaration of function ‘strerror_r’ [-Wimplicit-function-declaration]
errorLogger.c: In function ‘logMessage’:
errorLogger.c:87:5: warning: implicit declaration of function ‘localtime_r’ [-Wimplicit-function-declaration]
errorLogger.c: In function ‘processErrorQueue’:
errorLogger.c:131:17: warning: implicit declaration of function ‘open’ [-Wimplicit-function-declaration]
errorLogger.c:131:57: error: ‘O_APPEND’ undeclared (first use in this function)
errorLogger.c:131:57: note: each undeclared identifier is reported only once for each function it appears in
errorLogger.c:131:68: error: ‘O_CREAT’ undeclared (first use in this function)
errorLogger.c:131:78: error: ‘O_WRONLY’ undeclared (first use in this function)
errorLogger.c:131:88: error: ‘S_IWRITE’ undeclared (first use in this function)
errorLogger.c:131:99: error: ‘S_IREAD’ undeclared (first use in this function)
errorLogger.c:146:13: warning: implicit declaration of function ‘fsync’ [-Wimplicit-function-declaration]
errorLogger.c: In function ‘startErrorLogger’:
errorLogger.c:167:36: error: ‘O_APPEND’ undeclared (first use in this function)
errorLogger.c:167:47: error: ‘O_CREAT’ undeclared (first use in this function)
errorLogger.c:167:57: error: ‘O_WRONLY’ undeclared (first use in this function)
errorLogger.c:167:67: error: ‘S_IWRITE’ undeclared (first use in this function)
errorLogger.c:167:78: error: ‘S_IREAD’ undeclared (first use in this function)
errorLogger.c:214:57: error: ‘O_EXCL’ undeclared (first use in this function)
errorLogger.c:231:27: warning: assignment makes integer from pointer without a cast [enabled by default]
errorLogger.c: In function ‘closeErrorLogger’:
errorLogger.c:246:9: warning: implicit declaration of function ‘pthread_kill’ [-Wimplicit-function-declaration]
In file included from errorLogger.h:24:0,
from global.h:18,
from global.c:9:
signalHandling.h:24:18: error: unknown type name ‘sigset_t’
In file included from main.c:23:0:
signalHandling.h:24:18: error: unknown type name ‘sigset_t’
main.c: In function ‘main’:
main.c:53:5: warning: implicit declaration of function ‘blockSignals’ [-Wimplicit-function-declaration]
main.c:61:45: error: invalid application of ‘sizeof’ to incomplete type ‘struct addrinfo’
main.c:62:29: error: invalid application of ‘sizeof’ to incomplete type ‘struct addrinfo’
main.c:64:10: error: dereferencing pointer to incomplete type
main.c:65:10: error: dereferencing pointer to incomplete type
main.c:66:10: error: dereferencing pointer to incomplete type
main.c:66:23: error: ‘AI_PASSIVE’ undeclared (first use in this function)
main.c:66:23: note: each undeclared identifier is reported only once for each function it appears in
main.c:69:5: warning: implicit declaration of function ‘getaddrinfo’ [-Wimplicit-function-declaration]
main.c:73:9: warning: implicit declaration of function ‘gai_strerror’ [-Wimplicit-function-declaration]
main.c:73:9: warning: format ‘%s’ expects argument of type ‘char *’, but argument 4 has type ‘int’ [-Wformat]
main.c:73:9: warning: format ‘%s’ expects argument of type ‘char *’, but argument 4 has type ‘int’ [-Wformat]
main.c:81:41: error: dereferencing pointer to incomplete type
main.c:83:30: error: dereferencing pointer to incomplete type
main.c:83:46: error: dereferencing pointer to incomplete type
main.c:83:64: error: dereferencing pointer to incomplete type
main.c:96:30: error: dereferencing pointer to incomplete type
main.c:96:44: error: dereferencing pointer to incomplete type
main.c:112:5: warning: implicit declaration of function ‘freeaddrinfo’ [-Wimplicit-function-declaration]
main.c:138:9: error: unknown type name ‘fd_set’
main.c:142:9: warning: implicit declaration of function ‘FD_ZERO’ [-Wimplicit-function-declaration]
main.c:143:9: warning: implicit declaration of function ‘FD_SET’ [-Wimplicit-function-declaration]
main.c:145:9: warning: implicit declaration of function ‘pselect’ [-Wimplicit-function-declaration]
In file included from signalHandling.c:10:0:
signalHandling.h:24:18: error: unknown type name ‘sigset_t’
signalHandling.c:12:18: error: unknown type name ‘sigset_t’
signalHandling.c: In function ‘setHandler’:
signalHandling.c:51:53: error: invalid application of ‘sizeof’ to incomplete type ‘struct sigaction’
signalHandling.c:52:36: error: invalid application of ‘sizeof’ to incomplete type ‘struct sigaction’
signalHandling.c:54:5: warning: implicit declaration of function ‘sigemptyset’ [-Wimplicit-function-declaration]
signalHandling.c:54:30: error: dereferencing pointer to incomplete type
signalHandling.c:60:9: warning: implicit declaration of function ‘sigaddset’ [-Wimplicit-function-declaration]
signalHandling.c:60:35: error: dereferencing pointer to incomplete type
signalHandling.c:67:17: error: dereferencing pointer to incomplete type
signalHandling.c:72:9: warning: implicit declaration of function ‘sigaction’ [-Wimplicit-function-declaration]
You are probably missing some #includes which are brought in implicitly on OS X, but not on Linux.
Judging from the error messages, you are probably missing includes for at least:
<signal.h> (for sigset_t and others)
<fcntl.h> (for O_*)
<unistd.h> (for a bunch of stuff)
<netdb.h> (for various network functions and constants)
<stdio.h> (for getline)
You may also need to define some feature macros (e.g, _POSIX_C_SOURCE) to get certain system-dependent functions, including strerror_r and pselect.
I'm assuming that the immediate objective is to get the code to compile at all, and that once that's done, you'll go back and revise the source so it works out of the box on both platforms. That means that hacks are acceptable very short-term; they'll be fixed properly as you gain knowledge about what the portability issues are. (If it's any consolation, the first alternative system to the one where the software was originally developed is usually the hardest; after that, it generally gets easier.)
The first thing to try is:
gcc *.c -std=gnu99 -lpthread
This tells system header files to define many more symbols than -std=c99. (There's some dissent on this topic, which is OK. At the least, if you add -pedantic to a -std=c99 compilation, then symbols in standard C headers defined by POSIX are not exposed unless you also request POSIX support — see below. Since you don't have -pedantic, that may not be a factor in the compilations, in which case quietly move on to the next recommendation, which is the basis for future portability to POSIX systems.)
If that is insufficient to get you back on track, then you'll probably need to use something like:
gcc *.c -std=gnu99 -D_XOPEN_SOURCE=700 -lpthread
This says "Provide me with the POSIX and X/Open functions corresponding to POSIX 2008". You can try 600 and 500 for older versions, but you probably won't need to do so on Linux. In due course, you're likely to set _XOPEN_SOURCE automatically, either through a configuration header or via a configuration tool. While you're getting things to compile at all, specifying it on the command line is OK. In due course, you'll be using a makefile or equivalent to control the compilation and not typing a gcc command line at the shell.)
The sigset_t is defined in <signal.h> under POSIX. So, requesting POSIX support explicitly should get things to compile again properly. If you still get types such as sigset_t undeclared, then there must be a header on Mac OS X that includes the standard headers such as <signal.h> but which does some unrelated task on Linux (and therefore does not include <signal.h>). That will require source code scrutiny. However, it is relatively unlikely to be necessary.
You need to include additional header files because different system headers include other different system headers.
Also for example gcc has been working hard to not included headers that it should not.
Is signalHandling.h including #include <signal.h> where sigset_t is defined?
EDIT
After talking with the OP it seems the problems was a compile/link problem. Compiling the source into object files first and then linking them after seemed to have solved their problem.

troubles with implicit declaration static (compiling customized mupdf library)

I am compiling mupdf with a custom version of some functions in mupdf library. There are two functions that seem to call each other so when I create the _custom version of them an error is issued at compile time.
pc#pc:~/sviluppo/mupdf-0.9$ make
CC build/debug/obj_print.o
fitz/obj_print.c: In function ‘fmt_array_custom’:
fitz/obj_print.c:191:4: warning: implicit declaration of function ‘fmt_obj_custom’
fitz/obj_print.c: At top level:
fitz/obj_print.c:304:13: warning: conflicting types for ‘fmt_obj_custom’
fitz/obj_print.c:304:13: error: static declaration of ‘fmt_obj_custom’ follows non-static declaration
fitz/obj_print.c:191:4: note: previous implicit declaration of ‘fmt_obj_custom’ was here
make: *** [build/debug/obj_print.o] Errore 1
What's wrong? the default version of the functions already call each other the same way.
In line 191, the function fmt_array_custom is called without prior declaration. So the compiler implicitly assumes a declaration (non-static).
Later in line 304, it sees the actual function declaration/definition which is static. This is a conflict.
For fixing this you can add a declaration before line 191. Just copy the function proto-type (without the body) from line 304.

act.offensive.c: In function âdo_fireâ: act.offensive.c:631: warning: incompatible implicit declaration of built-in function âabortâ

I'm rather new to coding but when compiling ( I use putty and SHH ) i receive this error
act.offensive.c:631: warning: incompatible implicit declaration of built-in function âabortâ
act.offensive.c:637: warning: incompatible implicit declaration of built-in function âabortâ
On lines 631 and 637
CREATE (lodged->next, LODGED_OBJECT_INFO, 1);
CREATE (target->lodged, LODGED_OBJECT_INFO, 1);
I did a search for aaborta and abort through the files in the SRC (for the compile) directory and did not find a match anywhere to explain it or find the file to index it to.
I was wondering if someone might be able to help me
You could try including <stdlib.h> in the file where the built-in function abort is declared.
The error message says about incompatible implicit declaration, so it might be that there's no explicit declaration anywhere in your code and the macro CREATE (I believe it's a macro?) tries to use it.
If that doesn't help, it'd be helpful if you could edit your question and describe what's CREATE in your code.

Resources