# arm64 kernel build ld -m "unknown emulation"



## escape (Oct 20, 2019)

Hi

Does anyone know how to work around:
`--- accf_data.kld ---
ld -m  -d -warn-common --build-id=sha1 -r -d -o accf_data.kld accf_data.o
--- modules-all ---
ld: error: unknown emulation: -d
*** [accf_data.kld] Error code 1`

It is missing something after the -m flag. Is it in elf format, 'aarch64elf' isn't it?

Compile is started with:
`export BASEDIR=/usr
export MAKEOBJDIRPREFIX=$BASEDIR/obj
make buildworld TARGET_ARCH=aarch64
make -j4 buildkernel TARGET_ARCH=aarch64 KERNCONF=MYCONF`

`buildworld` worked ok. Just to try something (if this helps), if the following is added in front of the make: `LDFLAGS=" -m aarch64elf"` It errors and if it is changed to `LDFLAGS=" aarch64elf"` the text 'aarch64elf' appears after the '-m' and the build goes just a bit further, until the next step. And it don't help.


e


----------



## yuripv (Oct 20, 2019)

Try `TARGET=arm64 TARGET_ARCH=aarch64`.

BTW, are there any overrides in /etc/make.conf and/or /etc/src.conf? What is the build system version, and what is the built source version?


----------



## escape (Oct 20, 2019)

All overrides (now unset), make.conf:

```
NO_CPU_CFLAGS=YES
```
Commands:
`make -j4 buildkernel TARGET=arm64 TARGET_ARCH=aarch64 KERNCONF=MYCONF`

It did not help.. The build failed with the same error.

Log:

```
--- modules-all ---
ctfconvert -L VERSION -g accf_data.o
--- accf_data.kld ---
ld -m  -d -warn-common --build-id=sha1 -r -d -o accf_data.kld accf_data.o
ld: error: unknown emulation: -d
*** [accf_data.kld] Error code 1

make[4]: stopped in /usr/src/sys/modules/accf_data
1 error

make[4]: stopped in /usr/src/sys/modules/accf_data
*** [all_subdir_accf_data] Error code 2
```

Built source version:

```
# svn info
Path: .
Working Copy Root Path: /usr/src
URL: https://svn.freebsd.org/base/stable/12
Relative URL: ^/stable/12
Repository Root: https://svn.freebsd.org/base
Repository UUID: ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
Revision: 353767
Node Kind: directory
Schedule: normal
Last Changed Author: dim
Last Changed Rev: 353765
Last Changed Date: 2019-10-19 18:58:20 +0300 (Sat, 19 Oct 2019)
```

How do I check the build system version?

```
# uname -a
FreeBSD name 12.0-STABLE FreeBSD 12.0-STABLE r343231 kernelname  amd64
# ld --version
LLD 6.0.1 (FreeBSD 335540-1200005) (compatible with GNU linkers)
# clang --version
FreeBSD clang version 6.0.1 (tags/RELEASE_601/final 335540) (based on LLVM 6.0.1)
Target: x86_64-unknown-freebsd12.0
Thread model: posix
InstalledDir: /usr/bin
```

Additional tests:
`#  make buildkernel TARGET=arm64 MACHINE=arm64 MACHINE_ARCH=aarch64 TARGET_ARCH=aarch64 KERNCONF=MYCONF`

This one went past the previous accf_data.kld but it stopped in another error:

```
cc -target aarch64-unknown-freebsd12.1 --sysroot=/data/marvell_obj/usr/src/arm64.aarch64/tmp -B/data/marvell_obj/usr/src/arm64.aarch64/tmp/usr/bin  -O2 -pipe  -fno-strict-aliasing -Werror -D_KERNEL -DKLD_MODULE -DKLD_TIED -nostdinc   -DHAVE_KERNEL_OPTION_HEADERS -include /data/marvell_obj/usr/src/arm64.aarch64/sys/MARVELDTS/opt_global.h -I. -I/usr/src/sys -I/usr/src/sys/contrib/ck/include -fno-common -g -fPIC -fdebug-prefix-map=./machine=/usr/src/sys/arm64/include -I/data/marvell_obj/usr/src/arm64.aarch64/sys/MARVELDTS   -MD  -MF.depend.aw_sid.o -MTaw_sid.o -mgeneral-regs-only -ffixed-x18 -ffreestanding -fwrapv -fstack-protector -gdwarf-2 -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wcast-qual -Wundef -Wno-pointer-sign -D__printf__=__freebsd_kprintf__ -Wmissing-include-dirs -fdiagnostics-show-option -Wno-unknown-pragmas -Wno-error-tautological-compare -Wno-error-empty-body -Wno-error-parentheses-equality -Wno-error-unused-function -Wno-error-pointer-sign -Wno-error-shift-negative-value -Wno-address-of-packed-member    -std=iso9899:1999 -c /usr/src/sys/arm/allwinner/aw_sid.c -o aw_sid.o
/usr/src/sys/arm/allwinner/aw_sid.c:53:10: fatal error: 'nvmem_if.h' file not found
#include "nvmem_if.h"
         ^~~~~~~~~~~~
1 error generated.
*** Error code 1

Stop.
make[5]: stopped in /usr/src/sys/modules/allwinner/aw_sid
*** Error code 1

Stop.
make[4]: stopped in /usr/src/sys/modules/allwinner
```

I have been reading https://wiki.freebsd.org/arm/crossbuild . If 'MACHINE...' variables should be the build systems I don't know. What are these environment variables? A good guide could help, some included: man build , man config , make target , not found.

e


----------



## acheron (Oct 21, 2019)

Your system is 8 months old, upgrade your system first and try again.


----------



## SirDice (Oct 21, 2019)

acheron said:


> upgrade your system first and try again.


Agreed, 12.1-STABLE also has a newer LLVM (8.0.1), the issue may already have been resolved.

```
dice@molly:~ % clang -v
FreeBSD clang version 8.0.1 (tags/RELEASE_801/final 366581) (based on LLVM 8.0.1)
Target: x86_64-unknown-freebsd12.1
Thread model: posix
InstalledDir: /usr/bin
dice@molly:~ % uname -a
FreeBSD molly.dicelan.home 12.1-STABLE FreeBSD 12.1-STABLE r353128 MOLLY  amd64
```


----------



## escape (Oct 22, 2019)

After svn update and installworld. The same.

```
$ uname -a
FreeBSD name 12.1-STABLE FreeBSD 12.1-STABLE r353778 kernelname  amd64
```

`make -j4 buildkernel  TARGET=arm64 TARGET_ARCH=aarch64 KERNCONF=MYCONF`


```
--- modules-all ---
ld -m  -d -warn-common --build-id=sha1 -r -d -o accf_data.kld accf_data.o
ld: error: unknown emulation: -d
*** [accf_data.kld] Error code 1

make[4]: stopped in /usr/src/sys/modules/accf_data
1 error
```


----------



## acheron (Oct 22, 2019)

With a clean /usr/obj?


----------



## SirDice (Oct 22, 2019)

Look at how Crochet does things. If you look at the settings for a Pi3 you'll notice that both `TARGET` and `TARGET_ARCH` are set to `aarch64`.

But, it hasn't been asked before, for what are you trying to cross-build? Tell us what you're trying to do.


----------



## acheron (Oct 22, 2019)

No need to set TARGET anyway. You can do `make TARGET_ARCH=aarch64` and it'll be fine.


----------



## acheron (Oct 22, 2019)

SirDice said:


> Look at how Crochet does things. If you look at the settings for a Pi3 you'll notice that both `TARGET` and `TARGET_ARCH` are set to `aarch64`.
> 
> But, it hasn't been asked before, for what are you trying to cross-build? Tell us what you're trying to do.


He tries to build the kernel (`make -j4 buildkernel TARGET=arm64 TARGET_ARCH=aarch64 KERNCONF=MYCONF`)


----------



## SirDice (Oct 22, 2019)

Yes, that's what is understood. But not the _why_. If we know what he's trying to accomplish we can provide better answers. Let's prevent an XY problem.


----------



## escape (Oct 22, 2019)

After adding a new device (nvram) the kernel compiled flawlessly with the MACHINE -flags. If I had not understood this not yet twice. In fact there has been an issue in the makefiles here at the LD_EMULATION or similar just at arm64. I just don't find the link anymore. the 'TARGET' is not enough with arm64. I was about to put a smilie in the post because someone answered but I don't like the talking what someone is about to do or why is he doing this. Ok, compiled a kernel:

```
make -j4 buildkernel MACHINE=arm64 MACHINE_ARCH=aarch64 TARGET=arm64 TARGET_ARCH=aarch64 KERNCONF=MYCONF
make -j4 installkernel TARGET_ARCH=aarch64 DESTDIR=/data/ARM64 KERNCONF=MYCONF
```

It did the trick and the problem was solved. If there is still something to fix adding documentation and this target is not enought for the arm64.

Thanks for the help.

e

Postscript, edit 12:th of January 2020:
The setting was kernel option:
`device          nvmem`
After setting the DTS option.


----------

