# Vault 7: Projects

This publication series is about specific projects related to the Vault 7 main publication.

### Protego

# MPLAB XC16 C-Compiler

- 1
- 2
…
- 136
- 137
- 138
- 139
- 140
…
- 365
- 366

MPLAB
®
XC16 C Compiler Users Guide
DS50002071C-page 138  2012-2013 Microchip Technology Inc.
The affect of the weak attribute on a definition is more complicated and requires
multiple files to describe:
/* weak1.c */
int
__attribute__((__weak__)) i;
void foo() {
i = 1;
}
/* weak2.c */
int i;
extern void foo(void);
void bar() {
i = 2;
}
main() {
foo();
bar();
}
Here the definition in weak2.c of i causes the symbol to become a strong definition.
No link error is emitted and both is refer to the same storage location. Storage is
allocated for weak1.cs version of i, but this space is not accessible.
There is no check to ensure that both versions of i have the same type; changing i in
weak2.c to be of type float will still allow a link, but the behavior of function foo will
be unexpected. foo will write a value into the least significant portion of our 32-bit float
value. Conversely, changing the type of the weak definition of i in weak1.c to type
float may cause disastrous results. We will be writing a 32-bit floating point value into
a 16-bit integer allocation, overwriting any variable stored immediately after our i.
In the cases where only weak definitions exist, the linker will choose the storage of the
first such definition. The remaining definitions become in-accessible.
The behavior is identical, regardless of the type of the symbol; functions and variables
behave in the same manner.

- 1
- 2
…
- 136
- 137
- 138
- 139
- 140
…
- 365
- 366