Changeset View
Changeset View
Standalone View
Standalone View
lib/csu/common/crtbrand.c
Show All 22 Lines | |||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||
*/ | */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
jhb: This seemed less work than getting it added into ACFLAGS in various places at least as a hack… | |||||
#include <sys/elf_common.h> | #include <sys/elf_common.h> | ||||
#include "notes.h" | |||||
/* | /* | ||||
* Special ".note" entry specifying the ABI version. See | * Special ".note" entry specifying the ABI version. See | ||||
* http://www.netbsd.org/Documentation/kernel/elf-notes.html | * http://www.netbsd.org/Documentation/kernel/elf-notes.html | ||||
* for more information. | * for more information. | ||||
* | |||||
* For all arches except sparc, gcc emits the section directive for the | |||||
* following struct with a PROGBITS type. However, newer versions of binutils | |||||
* (after 2.16.90) require the section to be of NOTE type, to guarantee that the | |||||
* .note.ABI-tag section correctly ends up in the first page of the final | |||||
* executable. | |||||
* | |||||
* Unfortunately, there is no clean way to tell gcc to use another section type, | |||||
* so this C file (or the C file that includes it) must be compiled in multiple | |||||
* steps: | |||||
* | |||||
* - Compile the .c file to a .s file. | |||||
* - Edit the .s file to change the 'progbits' type to 'note', for the section | |||||
* directive that defines the .note.ABI-tag section. | |||||
* - Compile the .s file to an object file. | |||||
* | |||||
* These steps are done in the invididual Makefiles for each applicable arch. | |||||
*/ | */ | ||||
static const struct { | __asm( | ||||
int32_t namesz; | " .section .note.tag,\"a\",@note\n" | ||||
int32_t descsz; | " .p2align 2\n" | ||||
int32_t type; | " .word 8\n" | ||||
char name[sizeof(NOTE_FREEBSD_VENDOR)]; | " .word 4\n" | ||||
int32_t desc; | " .word " __XSTRING(NT_FREEBSD_ABI_TAG) "\n" | ||||
} abitag __attribute__ ((section (NOTE_SECTION), aligned(4))) __used = { | " .asciz \"FreeBSD\"\n" | ||||
Not Done Inline ActionsI would be explicit with the NULs to be clear this is exactly 8 bytes as we need to ensure 4-byte alignment of the following word (and to match the namesz above). jrtc27: I would be explicit with the NULs to be clear this is exactly 8 bytes as we need to ensure 4… | |||||
Done Inline ActionsThe alternative might be to throw in a .p2align 2 to enforce the padding? jhb: The alternative might be to throw in a `.p2align 2` to enforce the padding? | |||||
Not Done Inline ActionsThen it's less clear that namesz is correct. jrtc27: Then it's less clear that namesz is correct. | |||||
Done Inline ActionsSo I could use labels to derive namesz (and perhaps even descsz) as the NetBSD webpage suggests. jhb: So I could use labels to derive namesz (and perhaps even descsz) as the NetBSD webpage suggests. | |||||
Not Done Inline ActionsAh yes, that would work. jrtc27: Ah yes, that would work. | |||||
Not Done Inline ActionsSounds good to me. emaste: Sounds good to me. | |||||
.namesz = sizeof(NOTE_FREEBSD_VENDOR), | " .p2align 2\n" | ||||
.descsz = sizeof(int32_t), | " .word " __XSTRING(__FreeBSD_version)); | ||||
.type = NT_FREEBSD_ABI_TAG, | |||||
.name = NOTE_FREEBSD_VENDOR, | |||||
.desc = __FreeBSD_version | |||||
}; | |||||
static const struct { | __asm( | ||||
int32_t namesz; | " .section .note.tag,\"a\",@note\n" | ||||
int32_t descsz; | " .p2align 2\n" | ||||
int32_t type; | " .word 8\n" | ||||
char name[sizeof(NOTE_FREEBSD_VENDOR)]; | " .word 4\n" | ||||
uint32_t desc[1]; | " .word " __XSTRING(NT_FREEBSD_FEATURE_CTL) "\n" | ||||
} crt_feature_ctl __attribute__ ((section (NOTE_SECTION), | " .asciz \"FreeBSD\"\n" | ||||
aligned(4))) __used = { | " .p2align 2\n" | ||||
.namesz = sizeof(NOTE_FREEBSD_VENDOR), | " .word 0"); | ||||
.descsz = sizeof(uint32_t), | |||||
.type = NT_FREEBSD_FEATURE_CTL, | |||||
.name = NOTE_FREEBSD_VENDOR, | |||||
.desc = { 0 } | |||||
}; |
This seemed less work than getting it added into ACFLAGS in various places at least as a hack, but I'd be fine moving this out to ACFLAGS if that is preferred.