‘struct in6_addr’ has no member named ‘s6_addr32’ with -ansi - c

I'm working through some compile errors when building OpenSSL with no-asm -ansi. I'm catching the error:
$ ./config no-asm -ansi
...
$ make
...
gcc -DDSO_DLFCN -DHAVE_DLFCN_H -DOPENSSL_THREADS -DOPENSSL_NO_STATIC_ENGINE -DOPENSSL_PIC
-DOPENSSLDIR="\"/usr/local/ssl\"" -DENGINESDIR="\"/usr/local/lib/engines\"" -Wall -O3
-pthread -m64 -DL_ENDIAN -ansi -fPIC -Iinclude -I. -Icrypto/include -MMD -MF
crypto/bio/bss_dgram.d.tmp -MT crypto/bio/bss_dgram.o -c -o crypto/bio/bss_dgram.o
crypto/bio/bss_dgram.c
In file included from /usr/include/netdb.h:27:0,
from ./e_os.h:443,
from crypto/bio/bio_lcl.h:2,
from crypto/bio/bss_dgram.c:62:
crypto/bio/bss_dgram.c: In function ‘dgram_get_mtu_overhead’:
crypto/bio/bss_dgram.c:433:20: error: ‘const struct in6_addr’ has no member named ‘s6_addr32’
&& IN6_IS_ADDR_V4MAPPED(&tmp_addr))
^
I found the struct in /usr/include/linux/in6.h:
#if __UAPI_DEF_IN6_ADDR
struct in6_addr {
union {
__u8 u6_addr8[16];
#if __UAPI_DEF_IN6_ADDR_ALT
__be16 u6_addr16[8];
__be32 u6_addr32[4];
#endif
} in6_u;
#define s6_addr in6_u.u6_addr8
#if __UAPI_DEF_IN6_ADDR_ALT
#define s6_addr16 in6_u.u6_addr16
#define s6_addr32 in6_u.u6_addr32
#endif
};
#endif /* __UAPI_DEF_IN6_ADDR */
I don't recall needing to define __UAPI_DEF_IN6_ADDR_ALT in the past. Searching for it reveals the following from the kernel's libc-compat.h, line 95 or so (if I am parsing it correctly):
#define __UAPI_DEF_IN6_ADDR 1
/* We unconditionally define the in6_addr macros and glibc must coordinate. */
#define __UAPI_DEF_IN6_ADDR_ALT 1
#define __UAPI_DEF_SOCKADDR_IN6 1
#define __UAPI_DEF_IPV6_MREQ 1
#define __UAPI_DEF_IPPROTO_V6 1
#define __UAPI_DEF_IPV6_OPTIONS 1
#define __UAPI_DEF_IN6_PKTINFO 1
#define __UAPI_DEF_IP6_MTUINFO 1
How should I proceed to get the alternate symbols defined?
The system is Ubuntu 14.04 (x86_64):
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.4 LTS
Release: 14.04
Codename: trusty
GCC is:
$ gcc --version
gcc (Ubuntu 4.8.4-2ubuntu1~14.04.1) 4.8.4
Copyright (C) 2013 Free Software Foundation, Inc.

This turned out to be interesting... The short of it is I needed to add both -ansi and -D_DEFAULT_SOURCE=1. However, -D_DEFAULT_SOURCE=1 kind of undoes what -ansi is trying to accomplish so it needs to be contained.
First, /usr/include/linux/in6.h was the wrong header. I found it through a grep for struct in6_addr, and not tracing includes like needed to be done.
Next... -D_DEFAULT_SOURCE=1 indirectly came from /usr/include/netinet/in.h:
#ifndef __USE_KERNEL_IPV6_DEFS
/* IPv6 address */
struct in6_addr
{
union
{
uint8_t __u6_addr8[16];
#ifdef __USE_MISC
uint16_t __u6_addr16[8];
uint32_t __u6_addr32[4];
#endif
} __in6_u;
#define s6_addr __in6_u.__u6_addr8
#ifdef __USE_MISC
# define s6_addr16 __in6_u.__u6_addr16
# define s6_addr32 __in6_u.__u6_addr32
#endif
};
#endif /* !__USE_KERNEL_IPV6_DEFS */
Manually enabling __USE_MISC did not work. Tracing things for __USE_MISC in /usr/include/features.h:
/*
...
__USE_MISC Define things from 4.3BSD or System V Unix.
...
*/
#undef __USE_MISC
...
#if defined _DEFAULT_SOURCE
# define __USE_MISC 1
#endif
And finally, from a comment in /usr/include/features.h:
_DEFAULT_SOURCE The default set of features (taking precedence over __STRICT_ANSI__).
Though _DEFAULT_SOURCE=1 diverges from -ansi, the impact can be limited to the one source file that's affected by IN6_IS_ADDR_V4MAPPED. That is, in for the C source file crypto/bio/bss_dgram.c:
/* OpenSSL copyright ... */
#ifndef _DEFAULT_SOURCE
# define _DEFAULT_SOURCE 1
#endif
#include <stdio.h>
#include <errno.h>
#include <netinet/in.h>
...
Fiddling with __USE_KERNEL_IPV6_DEFS made things even worse. I believe it enabled /usr/include/linux/in6.h, which had similar (but completely different) member names than <netinet/in.h>.

Related

Undeclared Identifiers in header file with AVR-GCC

I created the following header file with definitions for AVR pins to be used in my code.
#define LED_PORT PORTB
#define LED_PIN PINB
#define LED_DDR DDRB
#define LED0 PB0
I encounter two failures I am not able to solve.
1) I have two issues in this header file, shown here:
2) Also the functions I created in the header file for USART in the USART.h file, I implemented, are not being recognized
I actually do not understand why that is. As the code clearly has the header file implemented.
#ifndef F_CPU
#define F_CPU 1000000UL
#endif
#include <avr/io.h>
#include <util/delay.h>
#include "pinDefinition.h"
#include "USART.h"
int main(void) {
char serialCharacter;
LED_DDR = 0xff;
initUSART();
printString("Hello World!\r\n");
while (1) {
serialCharacter = receiveByte();
transmitByte(serialCharacter);
LED_PORT = serialCharacter;
}
return (0);
}
The compiler I am using is AVR-GCC.
Furthermore, when I include the USART.c directly, then everything is working fine. I don't understand why the header file is not working though.
I created a script that runs the compiler/linker:
#!/bin/bash
avr-gcc -g -Os -mmcu=atmega328p -c code.c util.c USART.c
avr-gcc -g -mmcu=atmega328p -o code.elf code.o
avr-objcopy -j .text -j .data -O ihex code.elf code.hex
avr-size --format=avr --mcu=atmega328p code.elf
This returns the above mentioned error.
The USART.h looks like this:
/* These are defined for convenience */
#define USART_HAS_DATA bit_is_set(UCSR0A, RXC0)
#define USART_READY bit_is_set(UCSR0A, UDRE0)
#include <stdint.h>
void initUSART(void);
void transmitByte(uint8_t data);
uint8_t receiveByte(void);
void printString(const char myString[]);
void readString(char myString[], uint8_t maxLength);
void printByte(uint8_t byte);
void printWord(uint16_t word);
void printBinaryByte(uint8_t byte);
char nibbleToHex(uint8_t nibble);
char nibbleToHexCharacter(uint8_t nibble);
void printHexByte(uint8_t byte);
uint8_t getNumber(void);
I really require some help as I am trying to solve this now for three days and read a lot of different sources (I am getting my ropes together still with C so please be mindful).C
I created a script that runs the compiler/linker:
avr-gcc -g -Os -mmcu=atmega328p -c code.c util.c USART.c
This command generates three files: code.o, util.o and USART.o, whereas the following link command only links one object file:
avr-gcc -g -mmcu=atmega328p -o code.elf code.o
Hence, all functions from the latter two compilation units are missing, which leads tu bunch of "undefined reference to" from the linker. Fix is to link all three object files:
avr-gcc -g -mmcu=atmega328p -o code.elf code.o util.o USART.o
Undeclared Identifiers in header file
A header file (module.h) in C just contains declarations of functions in the module (module.c), but the implementation / definition of the functions is in the *.c file.
(One exception are static inline functions which are defined in the header, but this is not the case for the undefined references from your code.)

Postgresql 9.6 C function compile error: elog.h: unknown type 'sigjmp'

all,
I am trying to compile the following C skeleton against Postgresql 9.6.
#include "postgres.h"
#include "fmgr.h"
#include "miscadmin.h"
#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif
PG_FUNCTION_INFO_V1(calculateValHash);
Datum calculateValHash(PG_FUNCTION_ARGS) {
text *t = PG_GETARG_TEXT_P(0);
if ( t ) {
PG_RETURN_INT32(12);
} else {
PG_RETURN_INT32(1);
}
};
The following gcc command returns with error:
gcc -shared -I/usr/include/postgresql/9.6/server -lpq -o ./_build/magick.so pgmagick.c -std=c99 -Wall -Wextra
In file included from /usr/include/postgresql/9.6/server/postgres.h:48:0,
from pgmagick.c:1:
/usr/include/postgresql/9.6/server/utils/elog.h:318:20: error: unknown type name ‘sigjmp_buf’
extern PGDLLIMPORT sigjmp_buf *PG_exception_stack;
^
OS:Ubuntu 16.04.1 LTS
I have postgresql-server-dev-9.6 also installed.
According to man setjmp,
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
siglongjmp(): _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_C_SOURCE
Try to #define _XOPEN_SOURCE before #include "postgres.h".

compilation error on clock_gettime and CLOCK_MONOTONIC

I'm using clock_gettime in a program. I've tried including as well as but neither works. I have also added -lrt to my compiler arguments but still I get the same errors.
This is on
CentOS Linux release 7.2.1511 (Core)
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4)
GNU ld version 2.23.52.0.1-55.el7 20130226
ldd (GNU libc) 2.17
Compiler output:
gcc -o main packet.c connect.c transport.c accept.c main.c close.c util.c receive.c send.c congestion.c -Wall -g -std=c99 -lrt
util.c: In function ‘millis’:
util.c:42:21: error: storage size of ‘t’ isn’t known
struct timespec t;
^
util.c:43:5: warning: implicit declaration of function ‘clock_gettime’ [-Wimplicit-function-declaration]
clock_gettime(CLOCK_MONOTONIC_RAW, &t);
^
util.c:43:19: error: ‘CLOCK_MONOTONIC_RAW’ undeclared (first use in this function)
clock_gettime(CLOCK_MONOTONIC_RAW, &t);
^
Makefile
CFLAGS = -Wall -g -std=c99
LIBS = -lrt
# Should be equivalent to your list of C files, if you don't build selectively
SRC=$(wildcard *.c)
main: $(SRC)
gcc -o $# $^ $(CFLAGS) $(LIBS)
Top of util.h
#ifndef UTILS_438_H_
#define UTILS_438_H_
#include "const.h"
#include "data.h"
#include "transport.h"
#include <time.h>
Top of util.c
#include "util.h"
#include <time.h>
#include <stdio.h>
#include <string.h>
Please let me know if I can supply more information to help answer this
Before including the header(<time.h>), do
#define _POSIX_C_SOURCE 199309L
http://man7.org/linux/man-pages/man2/clock_gettime.2.html
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
clock_getres(), clock_gettime(), clock_settime():
_POSIX_C_SOURCE >= 199309L
http://man7.org/linux/man-pages/man7/feature_test_macros.7.html
_POSIX_C_SOURCE
Defining this macro causes header files to expose definitions as
follows:
· The value 1 exposes definitions conforming to POSIX.1-1990 and
ISO C (1990).
· The value 2 or greater additionally exposes definitions for
POSIX.2-1992.
· The value 199309L or greater additionally exposes definitions
for POSIX.1b (real-time extensions).
· The value 199506L or greater additionally exposes definitions
for POSIX.1c (threads).
· (Since glibc 2.3.3) The value 200112L or greater additionally
exposes definitions corresponding to the POSIX.1-2001 base
specification (excluding the XSI extension). This value also
causes C95 (since glibc 2.12) and C99 (since glibc 2.10)
features to be exposed (in other words, the equivalent of
defining _ISOC99_SOURCE).
· (Since glibc 2.10) The value 200809L or greater additionally
exposes definitions corresponding to the POSIX.1-2008 base
specification (excluding the XSI extension).
Simply replace -std=c99 with -std=gnu99.
Thisway you do not have to add _POSIX_C_SOURCE
if you can use the following linker and Compiler flags
CFLAGS = -g -Wall -std=c99 -D_POSIX_SOURCE -D_GNU_SOURCE
LDFLAGS = -lpthread -lrt
you can get the build done in the Linux systems. -lrt linker and -D_POSIX_SOURCE are the important ones

Identifier not loaded in c

I am trying to run a example on handling signals, and it fails compiling on a unfound identifier.
Here is how the header is loaded :
#define __USE_GNU
#include <ucontext.h>
And the error when compiling (with gcc):
$ gcc -o sa_siginfo sa_siginfo.c
sa_siginfo.c: In function ‘bt_sighandler’:
sa_siginfo.c:25:28: error: ‘REG_RIP’ undeclared (first use in this function)
uc->uc_mcontext.gregs[REG_RIP]);
GCC info:
$ gcc --version
gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
/usr/include/ucontext.h does include /usr/include/sys/ucontext.h which has:
#ifdef __x86_64__
[...]
#ifdef __USE_GNU
/* Number of each register in the `gregset_t' array. */
enum
{
[...]
REG_RIP,
(My system is 64 bits)
So I don't understand why it doesn't find it ?
Try compiling your program like this
gcc -D_GNU_SOURCE -o sa_siginfo sa_siginfo.c
That __USE_GNU is defined only if you defined _GNU_SOURCE, and gcc will not define it by default.

Error: could not insert module. Unknown symbol in module

I'm trying to port RR0D Rasta Ring0 Debugger from 32-bit Linux to 64-bit Linux. I have converted 32-bit gcc inline assembly to 64-bit using vim regex as mentioned in my question: How to convert Linux 32-bit gcc inline assembly to 64-bit code?
I'm using gcc with -m64 flag. The target environment is Linux x86-64, custom kernel version 3.5.5.
The Makefile is the following:
EXTRA_CFLAGS += -O2 -Wall -DLINUX_26 -m64
OBJ := module_nux.o breakpoint.o buffering.o command.o disasmbak.o idt.o
OBJ += keyboard.o page.o video.o utils.o import_symb.o core_rr0d.o pci.o
MODULE := rr0d.o
obj-m := $(MODULE)
rr0d-objs := $(OBJ)
default:
make -C /lib/modules/`uname -r`/build/ SUBDIRS=`pwd` modules
clean:
rm -f *.o .*.o.cmd .*.ko.cmd *.mod.c *~
rm -rf .tmp_versions
mrproper:
make clean
rm -f *.ko
make gives a lot of warnings like warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] and warning: cast from pointer to integer of different size [-Wpointer-to-int-cast], but these are probably irrelevant to the topic.
The last rows of the output of make are probably the important ones:
/home/user/code/rr0d/0.3/core_rr0d.c: In function ‘cleanup_rr0d’:
/home/user/code/rr0d/0.3/core_rr0d.c:1938:36: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
CC [M] /home/user/code/rr0d/0.3/pci.o
LD [M] /home/user/code/rr0d/0.3/rr0d.o
Building modules, stage 2.
MODPOST 1 modules
WARNING: "RING_HOOO_SEGMENT" [/home/user/code/rr0d/0.3/rr0d.ko] undefined!
CC /home/user/code/rr0d/0.3/rr0d.mod.o
LD [M] /home/user/code/rr0d/0.3/rr0d.ko
make[1]: Leaving directory `/home/user/code/kernel/linux-3.5.5'
So, RING_HOOO_SEGMENT is undefined.
When I try to insmod the module with insmod ./rr0d.ko as root, I get:
Error: could not insert module ./rr0d.ko: Unknown symbol in module
Checking with dmesg | tail -n 1 gives the following output:
[15975.412346] rr0d: Unknown symbol RING_HOOO_SEGMENT (err 0)
So, the unknown symbol definitively is RING_HOOO_SEGMENT.
RING_HOOO_SEGMENT is a constant created with #define in vars.h, that is included in several .c files with #include "vars.h".
The essential #ifdef block of vars.h with #define RING_HOOO_SEGMENT is this one:
#ifdef LINUX_26
#define fake_naked
#if defined(__GNUC__)
// the line below is the important one.
#define RING_HOOO_SEGMENT "$0x7b"
//#define RING_HOOO_SEGMENT "$0x60"
#elif defined(_MSC_VER)
#define RING_HOOO_SEGMENT 0x7b
#endif
#else /* LINUX_24 */
#define fake_naked _asm_("\t" \
"add $0x08, %esp\n\t" \
"popl %ebp\n" \
);
#if defined(__GNUC__)
#define RING_HOOO_SEGMENT "$0x18"
#elif defined(_MSC_VER)
#define RING_HOOO_SEGMENT 0x18
#endif
#define RING_HOOO_SEGMENT_VALUE 0x18
#endif /* LINUX_26 */
Obviously if #define RING_HOOO_SEGMENT "$0x7b" (in #if defined(__GNUC__) inside #ifdef LINUX_26) is commented out, the code won't compile, so it's clear that RING_HOOO_SEGMENT gets defined.
Grepping for RING_HOOO_SEGMENT gives the following matches:
$ grep 'RING_HOOO_SEGMENT' *.c *.o *.ko
core_rr0d.c: "movq RING_HOOO_SEGMENT, %rax\n\t"\
core_rr0d.c: __asm{ movq RING_HOOO_SEGMENT, %rax}\
Binary file rr0d.ko matches
Both core_rr0d.c rows are inline assembly. core_rr0d.c contains #include "vars.h" so that should be fine.
Also the binary module rr0d.ko matches, so it contains the string RING_HOOO_SEGMENT (in some form), even if insmod ./rr0d.ko fails with Error: could not insert module ./rr0d.ko: Unknown symbol in module.
Any ideas what might the reason for this problem and how to proceed to be able to insmod the module?
core_rr0d.c: "movq RING_HOOO_SEGMENT, %rax\n\t"\
Here RING_HOOO_SEGMENT is in a string (probably part of an inline assembler block). As such, the preprocessor will not substitute RING_HOOO_SEGMENT, and it gets passed as-is to the assembler, where the definition of RING_HOOO_SEGMENT is not available.
Fortunately, RING_HOOO_SEGMENT is itself defined as the string "$0x7b", so we can use compile-time string concatenation:
"movq " RING_HOOO_SEGMENT ", %rax\n\t"\
The preprocessor will substitute RING_HOOO_SEGMENT for "$0x7b", then GCC will concatenate these strings before passing it down to the assembler.

Resources