2009년 02월 17일
[09.02.17] ARM 컴파일러에서 L6248E 에러
to <symname> in <attr2> region '<r2>'.
Example:
L6248E: foo.o(areaname) in ABSOLUTE region 'ER_RO' cannot have address/offset
type relocation to symbol in PI region 'ER_ZI'.
Applies to: ARM Developer Suite (ADS), RealView Developer Kit (RVDK) for OKI, RealView Developer Kit for XScale (RVXDK), RealView Developer Suite (RVDS) 2.0, RealView Developer Suite (RVDS) 2.1, RealView Developer Suite (RVDS) 2.2, RealView Development Suite (RVDS) 3.0, RealView Development Suite (RVDS) 3.1
링커는 "position independent" 코드를 시도할 때 에러를 발생할 수 있다. 다음 예제를 살펴보자
#include <stdio.h>
char *str = "test";
int main(void)
{
printf ("%s",str);
}
이 코드가 다음 링크 명령어와 컴파일 되게 되면:
armcc -c -apcs /ropi pi.c
armlink -ropi pi.o
링커는 다음과 같은 메시지를 보여준다.
Error: L6248E: pi.o(.data) in ABSOLUTE region 'ER_RW' cannot have address/offset type
relocation to .constdata in PI region 'ER_RO'.
위에 코드를 보면, 컴파일러는 global pointer str을 char string test를 가진 놈으로 생성한다. global pointer str은 .constdata 영역에서 char string "test"의 주소를 초기화해야 한다. 하지만, 절대 주소들은 PI 시스템에서 사용될 수 없으며, 그래서 링크 단계가 실패한다. (position independent).constdata의 ABS32 relocation 때문이다.
이를 해결하기 위해서는, 명시적인 포인터를 피하도록 코드를 재작성해야 한다. 두가지 가능한 방법을 살펴본다:
1) global pointer 대신 global array를 사용한다.
#include <stdio.h>
const char str[] = "test";
int main(void)
{
printf ("%s",str);
}
2) global pointer 대신 local pointer를 사용한다.
#include <stdio.h>
int main(void)
{
char *str = "test";
printf ("%s",str);
}
여러 개의 element들을 가진 list를 사용한다면 다음을 숙지하자:
char * list[] = {"zero", "one", "two"};배열에서 각 element를 위한 link error를 분리할 수도 있다. 이 경우에 추천되는 해결책은 다음과 같다.:
char list[3][5] = {"zero", "one", "two"};프린트를 할 때는 다음과 같이 한다(예시):
printf("%s", list[1]);리스트를 위한 이차원 배열을 선언해야 할 때 배열의 수로서 첫번째 dimension을 채우고, 두번째 dimension은 max 사이즈로 한다.
출처 :
# by | 2009/02/17 11:39 | - 프로개발자를 향하여 | 트랙백 | 덧글(0)



